From 720dc5e8c03e25310b94a265c08165dc7df179ba Mon Sep 17 00:00:00 2001 From: Saleh Souzanchi Date: Fri, 26 Apr 2013 09:09:40 +0430 Subject: [PATCH 1/2] fix currentRoute() when $_currentRoute is empty, return false --- lib/Cake/Routing/Router.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 740a439f3..3f05e5cbe 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -1093,7 +1093,8 @@ class Router { * @return CakeRoute Matching route object. */ public static function currentRoute() { - return self::$_currentRoute[count(self::$_currentRoute) - 1]; + $count = count(self::$_currentRoute) - 1; + return ($count >= 0) ? self::$_currentRoute[$count] : false; } /** From 4aabf72e1fbfc2e5e3d0a589b0a919ab0a094f98 Mon Sep 17 00:00:00 2001 From: Saleh Souzanchi Date: Fri, 26 Apr 2013 13:36:35 +0430 Subject: [PATCH 2/2] fix currentRoute() when $_currentRoute is empty, return false --- lib/Cake/Test/Case/Routing/RouterTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 109a1f293..3abe389c9 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -2161,6 +2161,16 @@ class RouterTest extends CakeTestCase { $this->assertEquals(Router::stripPlugin($url, null), $url); } +/** + * testCurrentRouteWhenNonExistentRoute + * + * @return void + */ + public function testCurrentRouteWhenNonExistentRoute() { + $route = Router::currentRoute(); + $this->assertFalse($route); + } + /** * testCurrentRoute *