Fix redirectUrl issue when loginRedirect is empty

Fixes #9819
This commit is contained in:
chinpei215 2016-12-04 20:06:24 +09:00
parent 307ad80358
commit b7481096c8
2 changed files with 16 additions and 0 deletions

View file

@ -742,6 +742,9 @@ class AuthComponent extends Component {
if (Router::normalize($redir) === Router::normalize($this->loginAction)) { if (Router::normalize($redir) === Router::normalize($this->loginAction)) {
$redir = $this->loginRedirect; $redir = $this->loginRedirect;
if (!$redir) {
$redir = '/';
}
} }
} elseif ($this->loginRedirect) { } elseif ($this->loginRedirect) {
$redir = $this->loginRedirect; $redir = $this->loginRedirect;

View file

@ -1652,6 +1652,19 @@ class AuthComponentTest extends CakeTestCase {
Router::reload(); Router::reload();
} }
/**
* Test that redirectUrl() returns '/' if loginRedirect is empty
* and Auth.redirect is the login page.
*
* @return void
*/
public function testRedirectUrlWithoutLoginRedirect() {
$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 * test password hashing
* *