diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index 741ed14..2bc42e3 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -605,7 +605,6 @@ abstract class Module extends Component if ($route === '') { $route = $this->defaultRoute; } - $route = trim($route, '/'); if (($pos = strpos($route, '/')) !== false) { $id = substr($route, 0, $pos); $route = substr($route, $pos + 1); diff --git a/framework/yii/web/Request.php b/framework/yii/web/Request.php index 03d37bc..d864d95 100644 --- a/framework/yii/web/Request.php +++ b/framework/yii/web/Request.php @@ -417,13 +417,13 @@ class Request extends \yii\base\Request */ public function setPathInfo($value) { - $this->_pathInfo = trim($value, '/'); + $this->_pathInfo = ltrim($value, '/'); } /** * Resolves the path info part of the currently requested URL. * A path info refers to the part that is after the entry script and before the question mark (query string). - * The starting and ending slashes are both removed. + * The starting slashes are both removed (ending slashes will be kept). * @return string part of the request URL that is after the entry script and before the question mark. * Note, the returned path info is decoded. * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration @@ -465,7 +465,7 @@ class Request extends \yii\base\Request throw new InvalidConfigException('Unable to determine the path info of the current request.'); } - return trim($pathInfo, '/'); + return ltrim($pathInfo, '/'); } /** diff --git a/framework/yii/web/UrlManager.php b/framework/yii/web/UrlManager.php index bd25dca..ce93548 100644 --- a/framework/yii/web/UrlManager.php +++ b/framework/yii/web/UrlManager.php @@ -29,6 +29,7 @@ class UrlManager extends Component /** * @var boolean whether to enable strict parsing. If strict parsing is enabled, the incoming * requested URL must match at least one of the [[rules]] in order to be treated as a valid request. + * Otherwise, the path info part of the request will be treated as the requested route. * This property is used only when [[enablePrettyUrl]] is true. */ public $enableStrictParsing = false; @@ -181,7 +182,7 @@ class UrlManager extends Component } $suffix = (string)$this->suffix; - if ($suffix !== '' && $suffix !== '/' && $pathInfo !== '') { + if ($suffix !== '' && $pathInfo !== '') { $n = strlen($this->suffix); if (substr($pathInfo, -$n) === $this->suffix) { $pathInfo = substr($pathInfo, 0, -$n); diff --git a/framework/yii/web/UrlRule.php b/framework/yii/web/UrlRule.php index 4b15601..ec73c92 100644 --- a/framework/yii/web/UrlRule.php +++ b/framework/yii/web/UrlRule.php @@ -192,8 +192,7 @@ class UrlRule extends Object // suffix alone is not allowed return false; } - } elseif ($suffix !== '/') { - // we allow the ending '/' to be optional if it is a suffix + } else { return false; } } diff --git a/tests/unit/framework/web/UrlManagerTest.php b/tests/unit/framework/web/UrlManagerTest.php index d192902..efa6695 100644 --- a/tests/unit/framework/web/UrlManagerTest.php +++ b/tests/unit/framework/web/UrlManagerTest.php @@ -163,9 +163,9 @@ class UrlManagerTest extends TestCase $result = $manager->parseRequest($request); $this->assertEquals(array('module/site/index', array()), $result); // pathinfo with trailing slashes - $request->pathInfo = 'module/site/index/'; + $request->pathInfo = '/module/site/index/'; $result = $manager->parseRequest($request); - $this->assertEquals(array('module/site/index', array()), $result); + $this->assertEquals(array('module/site/index/', array()), $result); // pretty URL rules $manager = new UrlManager(array( @@ -182,10 +182,10 @@ class UrlManagerTest extends TestCase $request->pathInfo = 'post/123/this+is+sample'; $result = $manager->parseRequest($request); $this->assertEquals(array('post/view', array('id' => '123', 'title' => 'this+is+sample')), $result); - // matching pathinfo with trailing slashes + // trailing slash is significant $request->pathInfo = 'post/123/this+is+sample/'; $result = $manager->parseRequest($request); - $this->assertEquals(array('post/view', array('id' => '123', 'title' => 'this+is+sample')), $result); + $this->assertEquals(array('post/123/this+is+sample/', array()), $result); // empty pathinfo $request->pathInfo = ''; $result = $manager->parseRequest($request); diff --git a/tests/unit/framework/web/UrlRuleTest.php b/tests/unit/framework/web/UrlRuleTest.php index f697805..3f1c070 100644 --- a/tests/unit/framework/web/UrlRuleTest.php +++ b/tests/unit/framework/web/UrlRuleTest.php @@ -620,7 +620,8 @@ class UrlRuleTest extends TestCase 'suffix' => '/', ), array( - array('posts', 'post/index'), + array('posts/', 'post/index'), + array('posts', false), array('a', false), ), ),