Skip to content
Permalink
Browse files

Make return value of Controller:referer() consistent when returning l…

…ocal URLs.

Before this fix if referrer is available the local URL returned does not have
base appended but if a referrer is not found the URL returned using the default
URL passed as argument gets returned with base appended. This inconsistency
makes it difficult to have usage like
`return $this->redirect($this->referrer('/default'));` when the app is in a
subfolder as the base get appended twice.
  • Loading branch information...
ADmad committed Apr 19, 2016
1 parent 4697b8e commit 78be1eca9137a5ea8feede1e2ac3de2e7244db5c
Showing with 13 additions and 2 deletions.
  1. +12 −1 src/Controller/Controller.php
  2. +1 −1 tests/TestCase/Controller/ControllerTest.php
@@ -645,7 +645,18 @@ public function referer($default = null, $local = false)
$referer = $this->request->referer($local);
if ($referer === '/' && $default && $default !== $referer) {
return Router::url($default, !$local);
$url = Router::url($default, !$local);
if ($local
&& $this->request->base
&& strpos($url, $this->request->base) === 0
) {
$url = substr($url, strlen($this->request->base));
if ($url[0] !== '/') {
$url = '/' . $url;
}
return $url;
}
return $url;
}
return $referer;
}
@@ -626,7 +626,7 @@ public function testRefererSlash()
$controller = new Controller($request);
$result = $controller->referer('/some/path', true);
$this->assertEquals('/base/some/path', $result);
$this->assertEquals('/some/path', $result);
}
/**

0 comments on commit 78be1ec

Please sign in to comment.
You can’t perform that action at this time.