Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix / being handled incorrect by referer()
When the referer is `/` Controller::referer() should not be appending
the base path as it results in the base path being added twice causing
incorrect results in AuthComponent.

Refs #4812
  • Loading branch information
markstory committed Oct 26, 2014
1 parent 1f3fa57 commit 32f8752
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -604,7 +604,7 @@ public function referer($default = null, $local = false) {
}

$referer = $this->request->referer($local);
if ($referer === '/' && $default) {
if ($referer === '/' && $default && $default !== $referer) {
return Router::url($default, !$local);
}
return $referer;
Expand Down
24 changes: 24 additions & 0 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -574,6 +574,30 @@ public function testReferer() {
$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('Cake\Network\Request', ['referer']);
$request->base = '/base';
Router::pushRequest($request);

$request->expects($this->any())->method('referer')
->will($this->returnValue('/'));

$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
*
Expand Down
7 changes: 0 additions & 7 deletions tests/test_app/TestApp/Controller/PagesController.php
Expand Up @@ -39,13 +39,6 @@ class PagesController extends AppController {
*/
public $helpers = array('Html', 'Session');

/**
* This controller does not use a model
*
* @var array
*/
public $uses = array();

/**
* Displays a view
*
Expand Down

0 comments on commit 32f8752

Please sign in to comment.