Skip to content

Commit

Permalink
Fix 'Uninitialized string offset: 0' for php7 when coming from home page
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed May 9, 2016
1 parent 6a463bb commit 0de5b1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Network/Request.php
Expand Up @@ -547,6 +547,9 @@ public function referer($local = false)
if (!empty($ref) && !empty($base)) {
if ($local && strpos($ref, $base) === 0) {
$ref = substr($ref, strlen($base));
if (empty($ref)) {
$ref = '/';
}
if ($ref[0] !== '/') {
$ref = '/' . $ref;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -574,6 +574,10 @@ public function testReferer()
$result = $request->referer(true);
$this->assertSame('/some/path', $result);

$request->env('HTTP_REFERER', Configure::read('App.fullBaseUrl') . '/');
$result = $request->referer(true);
$this->assertSame('/', $result);

$request->env('HTTP_REFERER', Configure::read('App.fullBaseUrl') . '/some/path');
$result = $request->referer(false);
$this->assertSame(Configure::read('App.fullBaseUrl') . '/some/path', $result);
Expand Down

0 comments on commit 0de5b1d

Please sign in to comment.