mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix / being handled incorrect by referer()
Backport changes in #4987 to 2.x. This solves issues with duplicate base directories when redirecting back to '/' Fixes #4812
This commit is contained in:
parent
ac5ba9942b
commit
396d501d1e
2 changed files with 25 additions and 1 deletions
|
@ -974,7 +974,7 @@ class Controller extends Object implements CakeEventListener {
|
|||
}
|
||||
|
||||
$referer = $this->request->referer($local);
|
||||
if ($referer === '/' && $default) {
|
||||
if ($referer === '/' && $default && $default !== $referer) {
|
||||
return Router::url($default, !$local);
|
||||
}
|
||||
return $referer;
|
||||
|
|
|
@ -1031,6 +1031,30 @@ class ControllerTest extends CakeTestCase {
|
|||
$this->assertEquals('/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the referer is not absolute if it is '/'.
|
||||
*
|
||||
* This avoids the base path being applied twice on string urls.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRefererSlash() {
|
||||
$request = $this->getMock('CakeRequest', array('referer'));
|
||||
$request->base = '/base';
|
||||
$request->expects($this->any())
|
||||
->method('referer')
|
||||
->will($this->returnValue('/'));
|
||||
Router::setRequestInfo($request);
|
||||
|
||||
$controller = new Controller($request);
|
||||
$result = $controller->referer('/', true);
|
||||
$this->assertEquals('/', $result);
|
||||
|
||||
$controller = new Controller($request);
|
||||
$result = $controller->referer('/some/path', true);
|
||||
$this->assertEquals('/base/some/path', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSetAction method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue