diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 53a39ba3fe..2aef9347f1 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -55,6 +55,7 @@ Yii Framework 2 Change Log - Bug #10580: Fixed `yii\grid\GridView::guessColumns()` to work with numeric column names (silverfire) - Bug #10625: Fixed `activeForm.js` - when submit doesn't reload page, submit button value simulation with hidden input did not work (andrewnester) - Bug #10629: Fixed `yii\helpers\BaseStringHelper` - BaseStringHelper::truncateHtml adds suffix regardless of the string length (andrewnester) +- Bug #10739: Fixed `yii\web\UrlManager::parseRequest()` to treat request URL with more than one slash at the end as invalid (andrewnester) - Bug #10751: Fixed `yii\validators\UrlValidator` pattern to improve matching (silverfire) - Bug: Fixed generation of canonical URLs for `ViewAction` pages (samdark) - Bug: Fixed `mb_*` functions calls to use `UTF-8` or `Yii::$app->charset` (silverfire) diff --git a/framework/web/UrlManager.php b/framework/web/UrlManager.php index 4a8664f1bc..c0efd1969d 100644 --- a/framework/web/UrlManager.php +++ b/framework/web/UrlManager.php @@ -242,6 +242,11 @@ class UrlManager extends Component Yii::trace('No matching URL rules. Using default URL parsing logic.', __METHOD__); + // Ensure, that $pathInfo does not end with more than one slash. + if (strlen($pathInfo) > 1 && substr_compare($pathInfo, '//', -2, 2) === 0) { + return false; + } + $suffix = (string) $this->suffix; if ($suffix !== '' && $pathInfo !== '') { $n = strlen($this->suffix); diff --git a/tests/framework/web/UrlManagerTest.php b/tests/framework/web/UrlManagerTest.php index 3d24de33f1..a6ab86d2a0 100644 --- a/tests/framework/web/UrlManagerTest.php +++ b/tests/framework/web/UrlManagerTest.php @@ -431,4 +431,47 @@ class UrlManagerTest extends TestCase $url = $manager->createAbsoluteUrl(['site/test', '#' => 'testhash']); $this->assertEquals('http://example.com/index.php/testPage#testhash', $url); } + + /** + * Tests if multislashes not accepted at the end of URL if PrettyUrl is enabled + * + * @see https://github.com/yiisoft/yii2/issues/10739 + */ + public function testMultiSlashesAtTheEnd() + { + $manager = new UrlManager([ + 'enablePrettyUrl' => true, + ]); + + $request = new Request; + + $request->pathInfo = 'post/multi/slash/'; + $result = $manager->parseRequest($request); + $this->assertEquals(['post/multi/slash/', []], $result); + + $request->pathInfo = 'post/multi/slash//'; + $result = $manager->parseRequest($request); + $this->assertEquals(false, $result); + + $request->pathInfo = 'post/multi/slash////'; + $result = $manager->parseRequest($request); + $this->assertEquals(false, $result); + + $manager = new UrlManager([ + 'enablePrettyUrl' => true, + 'suffix' => '/' + ]); + + $request->pathInfo = 'post/multi/slash/'; + $result = $manager->parseRequest($request); + $this->assertEquals(['post/multi/slash', []], $result); + + $request->pathInfo = 'post/multi/slash//'; + $result = $manager->parseRequest($request); + $this->assertEquals(false, $result); + + $request->pathInfo = 'post/multi/slash///////'; + $result = $manager->parseRequest($request); + $this->assertEquals(false, $result); + } }