@ -4,6 +4,7 @@ Yii Framework 2 Change Log
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 #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)
@ -174,7 +174,7 @@ class UrlRule extends Object implements UrlRuleInterface
if (array_key_exists($name, $this->defaults)) {
$length = strlen($match[0][0]);
$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))?";
} else {
$tr["<$name>"] = "(?P<$name>$pattern)?";
@ -693,6 +693,18 @@ class UrlRuleTest extends TestCase
['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]],
];
}