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:
mark_story 2015-01-15 21:16:15 -05:00
parent ac5ba9942b
commit 396d501d1e
2 changed files with 25 additions and 1 deletions

View file

@ -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;

View file

@ -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
*