Browse Source

Fixes #6871: Fixed the bug that using defaults and hostnames in URL rules may cause an out-of-range index issue

tags/2.0.4
Qiang Xue 10 years ago
parent
commit
72c34cda1e
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/web/UrlRule.php
  3. 12
      tests/unit/framework/web/UrlRuleTest.php

1
framework/CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.4 under development 2.0.4 under development
----------------------- -----------------------
- Bug #6871: Fixed the bug that using defaults and hostnames in URL rules may cause an out-of-range index issue (qiangxue)
- Bug #7529: Fixed `yii\web\Response::sendContentAsFile()` that was broken in 2.0.3 (samdark) - Bug #7529: Fixed `yii\web\Response::sendContentAsFile()` that was broken in 2.0.3 (samdark)
- Bug #7603: Fixed escape characters in `FormatConverter` to work with unicode characters (maddoger, cebe) - Bug #7603: Fixed escape characters in `FormatConverter` to work with unicode characters (maddoger, cebe)
- Bug #7775: Added more strict check on controller IDs when they are being used to create controller instances on Windows (Bhoft, qiangxue) - Bug #7775: Added more strict check on controller IDs when they are being used to create controller instances on Windows (Bhoft, qiangxue)

2
framework/web/UrlRule.php

@ -174,7 +174,7 @@ class UrlRule extends Object implements UrlRuleInterface
if (array_key_exists($name, $this->defaults)) { if (array_key_exists($name, $this->defaults)) {
$length = strlen($match[0][0]); $length = strlen($match[0][0]);
$offset = $match[0][1]; $offset = $match[0][1];
if ($offset > 1 && $this->pattern[$offset - 1] === '/' && $this->pattern[$offset + $length] === '/') { if ($offset > 1 && $this->pattern[$offset - 1] === '/' && (!isset($this->pattern[$offset + $length]) || $this->pattern[$offset + $length] === '/')) {
$tr["/<$name>"] = "(/(?P<$name>$pattern))?"; $tr["/<$name>"] = "(/(?P<$name>$pattern))?";
} else { } else {
$tr["<$name>"] = "(?P<$name>$pattern)?"; $tr["<$name>"] = "(?P<$name>$pattern)?";

12
tests/unit/framework/web/UrlRuleTest.php

@ -693,6 +693,18 @@ class UrlRuleTest extends TestCase
['post/1/a', false], ['post/1/a', false],
], ],
], ],
[
'host info + defaults', // https://github.com/yiisoft/yii2/issues/6871
[
'pattern' => 'http://en.example.com/<page>',
'route' => 'post/index',
'defaults' => ['page' => 1],
],
[
['', 'post/index', ['page' => 1]],
['2', 'post/index', ['page' => 2]],
],
],
]; ];
} }
} }

Loading…
Cancel
Save