Redirects should always consider the base directory.

pull/135/head
Mike Cao 11 years ago
parent eefcd2b55a
commit c0fa0bed7c

@ -1 +1 @@
1.1.11 1.1.12

@ -409,9 +409,9 @@ class Engine {
$base = $this->request()->base; $base = $this->request()->base;
} }
// Append base to relative urls // Append base url to redirect url
if ($base != '/' && $url[0] != '/' && strpos($url, '://') === false) { if ($base != '/' && strpos($url, '://') === false) {
$url = $base.'/'.$url; $url = preg_replace('#/+#', '/', $base.'/'.$url);
} }
$this->response(false) $this->response(false)

@ -17,8 +17,8 @@ class RedirectTest extends PHPUnit_Framework_TestCase
private $app; private $app;
function getBaseUrl($base, $url){ function getBaseUrl($base, $url){
if ($base != '/' && $url[0] != '/' && strpos($url, '://') === false) { if ($base != '/' && strpos($url, '://') === false) {
return $base.'/'.$url; $url = preg_replace('#/+#', '/', $base.'/'.$url);
} }
return $url; return $url;
@ -38,12 +38,12 @@ class RedirectTest extends PHPUnit_Framework_TestCase
$this->assertEquals('/subdir', $base); $this->assertEquals('/subdir', $base);
} }
// Absolute URLs should ignore the base // Absolute URLs should include the base
function testAbsoluteUrl(){ function testAbsoluteUrl(){
$url = '/login'; $url = '/login';
$base = $this->app->request()->base; $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 // Relative URLs should include the base

Loading…
Cancel
Save