From c0fa0bed7c893694c640224db22a221d8bbdff4e Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 23 Jul 2014 00:39:00 -0700 Subject: [PATCH] Redirects should always consider the base directory. --- VERSION | 2 +- flight/Engine.php | 6 +++--- tests/RedirectTest.php | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 9ee1f78..ccad953 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.11 +1.1.12 diff --git a/flight/Engine.php b/flight/Engine.php index abb3c56..b26de60 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -409,9 +409,9 @@ class Engine { $base = $this->request()->base; } - // Append base to relative urls - if ($base != '/' && $url[0] != '/' && strpos($url, '://') === false) { - $url = $base.'/'.$url; + // Append base url to redirect url + if ($base != '/' && strpos($url, '://') === false) { + $url = preg_replace('#/+#', '/', $base.'/'.$url); } $this->response(false) diff --git a/tests/RedirectTest.php b/tests/RedirectTest.php index 7f006d8..fb43219 100644 --- a/tests/RedirectTest.php +++ b/tests/RedirectTest.php @@ -17,8 +17,8 @@ class RedirectTest extends PHPUnit_Framework_TestCase private $app; function getBaseUrl($base, $url){ - if ($base != '/' && $url[0] != '/' && strpos($url, '://') === false) { - return $base.'/'.$url; + if ($base != '/' && strpos($url, '://') === false) { + $url = preg_replace('#/+#', '/', $base.'/'.$url); } return $url; @@ -38,12 +38,12 @@ class RedirectTest extends PHPUnit_Framework_TestCase $this->assertEquals('/subdir', $base); } - // Absolute URLs should ignore the base + // Absolute URLs should include the base function testAbsoluteUrl(){ $url = '/login'; $base = $this->app->request()->base; - $this->assertEquals('/login', $this->getBaseUrl($base, $url)); + $this->assertEquals('/subdir/login', $this->getBaseUrl($base, $url)); } // Relative URLs should include the base