Browse Source

Fix #18548: Fix bug with REST rules with prefixes containing tokens not being parsed properly

tags/2.0.41.1
Bizley 4 years ago committed by GitHub
parent
commit
4997c51152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 6
      framework/rest/UrlRule.php
  3. 8
      tests/framework/rest/UrlRuleTest.php

1
framework/CHANGELOG.md

@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------ ------------------------
- Bug #18545: Reversed changes made to the `yii\db\Query::all()` and `indexBy` handling (bizley) - Bug #18545: Reversed changes made to the `yii\db\Query::all()` and `indexBy` handling (bizley)
- Bug #18548: Fix bug with REST rules with prefixes containing tokens not being parsed properly (bizley)
2.0.41 March 03, 2021 2.0.41 March 03, 2021

6
framework/rest/UrlRule.php

@ -216,7 +216,11 @@ class UrlRule extends CompositeUrlRule
public function parseRequest($manager, $request) public function parseRequest($manager, $request)
{ {
$pathInfo = $request->getPathInfo(); $pathInfo = $request->getPathInfo();
if ($this->prefix !== '' && strpos($pathInfo . '/', $this->prefix . '/') !== 0) { if (
$this->prefix !== ''
&& strpos($this->prefix, '<') === false
&& strpos($pathInfo . '/', $this->prefix . '/') !== 0
) {
return false; return false;
} }

8
tests/framework/rest/UrlRuleTest.php

@ -62,7 +62,6 @@ class UrlRuleTest extends TestCase
} }
} }
protected function getTestsForParseRequest() protected function getTestsForParseRequest()
{ {
// structure of each test // structure of each test
@ -162,6 +161,13 @@ class UrlRuleTest extends TestCase
['posts/1338', 'post/view', ['id' => 1338]], ['posts/1338', 'post/view', ['id' => 1338]],
], ],
], ],
[
'prefix with token',
['controller' => 'post', 'prefix' => 'admin/<name>'],
[
['admin/aaa/posts', 'post/index', ['name' => 'aaa']],
],
],
]; ];
} }

Loading…
Cancel
Save