diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index cb28f6e9c..2c56c5290 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -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) { diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 44bf6aacd..b4c956de0 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -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 *