Browse Source

Fixes #599

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
e433c98ed4
  1. 1
      framework/yii/base/Module.php
  2. 6
      framework/yii/web/Request.php
  3. 3
      framework/yii/web/UrlManager.php
  4. 3
      framework/yii/web/UrlRule.php
  5. 8
      tests/unit/framework/web/UrlManagerTest.php
  6. 3
      tests/unit/framework/web/UrlRuleTest.php

1
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);

6
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, '/');
}
/**

3
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);

3
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;
}
}

8
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);

3
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),
),
),

Loading…
Cancel
Save