Browse Source

Fix 'Uninitialized string offset: 0' for php7 when coming from home page

Òscar Casajuana 10 years ago
parent
commit
0de5b1d597
2 changed files with 7 additions and 0 deletions
  1. 3 0
      src/Network/Request.php
  2. 4 0
      tests/TestCase/Network/RequestTest.php

+ 3 - 0
src/Network/Request.php

@@ -547,6 +547,9 @@ class Request implements ArrayAccess
         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;
                 }

+ 4 - 0
tests/TestCase/Network/RequestTest.php

@@ -574,6 +574,10 @@ class RequestTest extends TestCase
         $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);