From 3ad68db5ebb71de3ed97950977ed6b452cca359a Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 2 Mar 2016 12:30:48 -0500 Subject: [PATCH] Tweak fix from #8359 This fixes a regression introduced in that change that we didn't previously have tests for. The issue fixed in #8359 was related to PHP7.0, whereas PHP5 didn't have an issue. Now both versions will work the same. --- lib/Cake/Network/CakeRequest.php | 5 ++++- lib/Cake/Test/Case/Network/CakeRequestTest.php | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 8933822e4..eb9cebd84 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -448,7 +448,10 @@ class CakeRequest implements ArrayAccess { if (!empty($ref) && !empty($base)) { if ($local && strpos($ref, $base) === 0) { $ref = substr($ref, strlen($base)); - if (isset($ref[0]) && $ref[0] !== '/') { + if (empty($ref)) { + $ref = '/'; + } + if ($ref[0] !== '/') { $ref = '/' . $ref; } return $ref; diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index e1c1d3598..90f92c7bf 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -742,6 +742,10 @@ class CakeRequestTest extends CakeTestCase { $result = $request->referer(); $this->assertSame($result, '/'); + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/'; + $result = $request->referer(true); + $this->assertSame($result, '/'); + $_SERVER['HTTP_REFERER'] = Configure::read('App.fullBaseUrl') . '/some/path'; $result = $request->referer(true); $this->assertSame($result, '/some/path');