mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
0d76bfe325
commit
1d18a4f702
2 changed files with 20 additions and 2 deletions
|
@ -651,8 +651,8 @@ class AuthComponent extends Component {
|
||||||
* If no parameter is passed, gets the authentication redirect URL. The URL
|
* If no parameter is passed, gets the authentication redirect URL. The URL
|
||||||
* returned is as per following rules:
|
* returned is as per following rules:
|
||||||
*
|
*
|
||||||
* - Returns the session Auth.redirect value if it is present and for the same
|
* - Returns the normalized URL from session Auth.redirect value if it is
|
||||||
* domain the current app is running on.
|
* 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
|
* - If there is no session value and there is a $loginRedirect, the $loginRedirect
|
||||||
* value is returned.
|
* value is returned.
|
||||||
* - If there is no session and no $loginRedirect, / 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);
|
$this->Session->write('Auth.redirect', $redir);
|
||||||
} elseif ($this->Session->check('Auth.redirect')) {
|
} elseif ($this->Session->check('Auth.redirect')) {
|
||||||
$redir = $this->Session->read('Auth.redirect');
|
$redir = $this->Session->read('Auth.redirect');
|
||||||
|
$redir = is_string($redir) ? ltrim($redir, '/') : $redir;
|
||||||
$this->Session->delete('Auth.redirect');
|
$this->Session->delete('Auth.redirect');
|
||||||
|
|
||||||
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
|
if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
|
||||||
|
|
|
@ -1235,6 +1235,23 @@ class AuthComponentTest extends CakeTestCase {
|
||||||
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
|
$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.
|
* test that redirect does not return loginAction if that is what's stored in Auth.redirect.
|
||||||
* instead loginRedirect should be used.
|
* instead loginRedirect should be used.
|
||||||
|
|
Loading…
Reference in a new issue