Commit e433c98e by Qiang Xue

Fixes #599

parent e3308996
...@@ -605,7 +605,6 @@ abstract class Module extends Component ...@@ -605,7 +605,6 @@ abstract class Module extends Component
if ($route === '') { if ($route === '') {
$route = $this->defaultRoute; $route = $this->defaultRoute;
} }
$route = trim($route, '/');
if (($pos = strpos($route, '/')) !== false) { if (($pos = strpos($route, '/')) !== false) {
$id = substr($route, 0, $pos); $id = substr($route, 0, $pos);
$route = substr($route, $pos + 1); $route = substr($route, $pos + 1);
......
...@@ -417,13 +417,13 @@ class Request extends \yii\base\Request ...@@ -417,13 +417,13 @@ class Request extends \yii\base\Request
*/ */
public function setPathInfo($value) public function setPathInfo($value)
{ {
$this->_pathInfo = trim($value, '/'); $this->_pathInfo = ltrim($value, '/');
} }
/** /**
* Resolves the path info part of the currently requested URL. * 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). * 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. * @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. * Note, the returned path info is decoded.
* @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration
...@@ -465,7 +465,7 @@ class Request extends \yii\base\Request ...@@ -465,7 +465,7 @@ class Request extends \yii\base\Request
throw new InvalidConfigException('Unable to determine the path info of the current request.'); throw new InvalidConfigException('Unable to determine the path info of the current request.');
} }
return trim($pathInfo, '/'); return ltrim($pathInfo, '/');
} }
/** /**
......
...@@ -29,6 +29,7 @@ class UrlManager extends Component ...@@ -29,6 +29,7 @@ class UrlManager extends Component
/** /**
* @var boolean whether to enable strict parsing. If strict parsing is enabled, the incoming * @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. * 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. * This property is used only when [[enablePrettyUrl]] is true.
*/ */
public $enableStrictParsing = false; public $enableStrictParsing = false;
...@@ -181,7 +182,7 @@ class UrlManager extends Component ...@@ -181,7 +182,7 @@ class UrlManager extends Component
} }
$suffix = (string)$this->suffix; $suffix = (string)$this->suffix;
if ($suffix !== '' && $suffix !== '/' && $pathInfo !== '') { if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($this->suffix); $n = strlen($this->suffix);
if (substr($pathInfo, -$n) === $this->suffix) { if (substr($pathInfo, -$n) === $this->suffix) {
$pathInfo = substr($pathInfo, 0, -$n); $pathInfo = substr($pathInfo, 0, -$n);
......
...@@ -192,8 +192,7 @@ class UrlRule extends Object ...@@ -192,8 +192,7 @@ class UrlRule extends Object
// suffix alone is not allowed // suffix alone is not allowed
return false; return false;
} }
} elseif ($suffix !== '/') { } else {
// we allow the ending '/' to be optional if it is a suffix
return false; return false;
} }
} }
......
...@@ -163,9 +163,9 @@ class UrlManagerTest extends TestCase ...@@ -163,9 +163,9 @@ class UrlManagerTest extends TestCase
$result = $manager->parseRequest($request); $result = $manager->parseRequest($request);
$this->assertEquals(array('module/site/index', array()), $result); $this->assertEquals(array('module/site/index', array()), $result);
// pathinfo with trailing slashes // pathinfo with trailing slashes
$request->pathInfo = 'module/site/index/'; $request->pathInfo = '/module/site/index/';
$result = $manager->parseRequest($request); $result = $manager->parseRequest($request);
$this->assertEquals(array('module/site/index', array()), $result); $this->assertEquals(array('module/site/index/', array()), $result);
// pretty URL rules // pretty URL rules
$manager = new UrlManager(array( $manager = new UrlManager(array(
...@@ -182,10 +182,10 @@ class UrlManagerTest extends TestCase ...@@ -182,10 +182,10 @@ class UrlManagerTest extends TestCase
$request->pathInfo = 'post/123/this+is+sample'; $request->pathInfo = 'post/123/this+is+sample';
$result = $manager->parseRequest($request); $result = $manager->parseRequest($request);
$this->assertEquals(array('post/view', array('id' => '123', 'title' => 'this+is+sample')), $result); $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/'; $request->pathInfo = 'post/123/this+is+sample/';
$result = $manager->parseRequest($request); $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 // empty pathinfo
$request->pathInfo = ''; $request->pathInfo = '';
$result = $manager->parseRequest($request); $result = $manager->parseRequest($request);
......
...@@ -620,7 +620,8 @@ class UrlRuleTest extends TestCase ...@@ -620,7 +620,8 @@ class UrlRuleTest extends TestCase
'suffix' => '/', 'suffix' => '/',
), ),
array( array(
array('posts', 'post/index'), array('posts/', 'post/index'),
array('posts', false),
array('a', false), array('a', false),
), ),
), ),
......
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