Fix parsing '0' as a url.

Fixes #3198
This commit is contained in:
mark_story 2012-09-09 20:56:40 -04:00
parent 9ac5cbed36
commit a934f700f1
2 changed files with 25 additions and 1 deletions

View file

@ -518,7 +518,7 @@ class Router {
$ext = null;
$out = array();
if ($url && strpos($url, '/') !== 0) {
if (strlen($url) && strpos($url, '/') !== 0) {
$url = '/' . $url;
}
if (strpos($url, '?') !== false) {

View file

@ -451,6 +451,30 @@ class RouterTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test that catch all routes work with a variety of falsey inputs.
*
* @return void
*/
public function testUrlCatchAllRoute() {
Router::connect('/*', array('controller' => 'categories', 'action' => 'index'));
$result = Router::url(array('controller' => 'categories', 'action' => 'index', '0'));
$this->assertEquals('/0', $result);
$expected = array(
'plugin' => null,
'controller' => 'categories',
'action' => 'index',
'pass' => array('0'),
'named' => array()
);
$result = Router::parse('/0');
$this->assertEquals($expected, $result);
$result = Router::parse('0');
$this->assertEquals($expected, $result);
}
/**
* Tests using arrays in named parameters
*