diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index 3e62e2cc9..54e7034ab 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -741,7 +741,7 @@ class AuthComponent extends Component { $this->Session->delete('Auth.redirect'); if (Router::normalize($redir) === Router::normalize($this->loginAction)) { - $redir = $this->loginRedirect; + $redir = $this->loginRedirect ?: '/'; } } elseif ($this->loginRedirect) { $redir = $this->loginRedirect; diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index 4514e5ec8..5da15d1e9 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -1652,6 +1652,20 @@ class AuthComponentTest extends CakeTestCase { Router::reload(); } +/** + * Test that redirectUrl() returns '/' if loginRedirect is empty + * and Auth.redirect is the login page. + * + * @return void + */ + public function testRedirectUrlWithoutLoginRedirect() { + $this->Auth->loginRedirect = null; + $this->Auth->Session->write('Auth.redirect', '/users/login'); + $this->Auth->request->addParams(Router::parse('/users/login')); + $result = $this->Auth->redirectUrl(); + $this->assertEquals('/', $result); + } + /** * test password hashing *