Skip to content

Commit

Permalink
Fix parsing '0' as a url.
Browse files Browse the repository at this point in the history
Fixes #3198
  • Loading branch information
markstory committed Sep 10, 2012
1 parent 9ac5cbe commit a934f70
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -518,7 +518,7 @@ public static function parse($url) {
$ext = null;
$out = array();

if ($url && strpos($url, '/') !== 0) {
if (strlen($url) && strpos($url, '/') !== 0) {
$url = '/' . $url;
}
if (strpos($url, '?') !== false) {
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -451,6 +451,30 @@ public function testUrlGenerationBasic() {
$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
*
Expand Down

0 comments on commit a934f70

Please sign in to comment.