Commit 8bff031f by Qiang Xue

Fixed the issue that dots in URL rules would match any character.

parent 817516ad
...@@ -156,6 +156,7 @@ class UrlRule extends Object ...@@ -156,6 +156,7 @@ class UrlRule extends Object
} }
} }
} }
$tr['.'] = '\\.';
$this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern); $this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern);
$this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u'; $this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u';
......
...@@ -380,6 +380,17 @@ class UrlRuleTest extends TestCase ...@@ -380,6 +380,17 @@ class UrlRuleTest extends TestCase
), ),
), ),
array( array(
'with dot', // https://github.com/yiisoft/yii/issues/2945
array(
'pattern' => 'posts.html',
'route' => 'post/index',
),
array(
array('posts.html', 'post/index'),
array('postsahtml', false),
),
),
array(
'creation only', 'creation only',
array( array(
'pattern' => 'posts', 'pattern' => 'posts',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment