Fix issue where redirectURLs were not generated correctly.

When the first path segment matches the base path an incorrect URL was
generated. Trimming slashes off makes Router normalize the URL correctly
as the leading / implies that the base is already prepended.

Fixes #3897
This commit is contained in:
mark_story 2013-06-29 23:24:26 -04:00
parent 0d76bfe325
commit 1d18a4f702
2 changed files with 20 additions and 2 deletions

View file

@ -651,8 +651,8 @@ class AuthComponent extends Component {
* If no parameter is passed, gets the authentication redirect URL. The URL
* returned is as per following rules:
*
* - Returns the session Auth.redirect value if it is present and for the same
* domain the current app is running on.
* - Returns the normalized URL from session Auth.redirect value if it is
* present and for the same domain the current app is running on.
* - If there is no session value and there is a $loginRedirect, the $loginRedirect
* value is returned.
* - If there is no session and no $loginRedirect, / is returned.
@ -666,6 +666,7 @@ class AuthComponent extends Component {
$this->Session->write('Auth.redirect', $redir);
} elseif ($this->Session->check('Auth.redirect')) {
$redir = $this->Session->read('Auth.redirect');
$redir = is_string($redir) ? ltrim($redir, '/') : $redir;
$this->Session->delete('Auth.redirect');
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {

View file

@ -1235,6 +1235,23 @@ class AuthComponentTest extends CakeTestCase {
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
}
/**
* test redirectUrl with duplicate base.
*
* @return void
*/
public function testRedirectSessionReadDuplicateBase() {
$this->Auth->request->webroot = '/waves/';
$this->Auth->request->base = '/waves';
Router::setRequestInfo($this->Auth->request);
$this->Auth->Session->write('Auth.redirect', '/waves/add');
$result = $this->Auth->redirectUrl();
$this->assertEquals('/waves/add', $result);
}
/**
* test that redirect does not return loginAction if that is what's stored in Auth.redirect.
* instead loginRedirect should be used.