From 8bff031fc235caa4fd085ab8a90a131a803cd040 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 10 Oct 2013 11:23:20 -0400 Subject: [PATCH] Fixed the issue that dots in URL rules would match any character. --- framework/yii/web/UrlRule.php | 1 + tests/unit/framework/web/UrlRuleTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/framework/yii/web/UrlRule.php b/framework/yii/web/UrlRule.php index ec73c92..10f0627 100644 --- a/framework/yii/web/UrlRule.php +++ b/framework/yii/web/UrlRule.php @@ -156,6 +156,7 @@ class UrlRule extends Object } } } + $tr['.'] = '\\.'; $this->_template = preg_replace('/<(\w+):?([^>]+)?>/', '<$1>', $this->pattern); $this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u'; diff --git a/tests/unit/framework/web/UrlRuleTest.php b/tests/unit/framework/web/UrlRuleTest.php index 0a0def4..5e57cb6 100644 --- a/tests/unit/framework/web/UrlRuleTest.php +++ b/tests/unit/framework/web/UrlRuleTest.php @@ -380,6 +380,17 @@ class UrlRuleTest extends TestCase ), ), 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', array( 'pattern' => 'posts',