From 5e18bfde98431222e0b22026afd2cdcfa65bd967 Mon Sep 17 00:00:00 2001 From: rkerner Date: Fri, 19 Dec 2014 16:45:58 +0100 Subject: [PATCH 1/2] * fixed baseUrl parsing ** added missing slash to baseUrl-path part check to remove the path, only when it's also a path in the uri * fixed and added unittests --- .../Component/HttpFoundation/Request.php | 2 +- .../HttpFoundation/Tests/RequestTest.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 5cfb7a48662c8..2765c6f7db8d3 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1693,7 +1693,7 @@ protected function prepareBaseUrl() return $prefix; } - if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl))) { + if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl) . '/')) { // directory portion of $baseUrl matches return rtrim($prefix, '/'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 1c93bbfee97e8..28be099284694 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -223,6 +223,21 @@ public function testCreate() $request = Request::create('http://test.com/?foo'); $this->assertEquals('/?foo', $request->getRequestUri()); $this->assertEquals(array('foo' => ''), $request->query->all()); + + ## assume rewrite rule: (.*) --> app/app.php ; app/ is a symlink to a symfony web/ directory + $request = Request::create('http://test.com/apparthotel-1234', 'GET', array(), array(), array(), + array( + 'DOCUMENT_ROOT' =>'/var/www/www.test.com', + 'SCRIPT_FILENAME' => '/var/www/www.test.com/app/app.php', + 'SCRIPT_NAME' => '/app/app.php', + 'PHP_SELF' => '/app/app.php/apparthotel-1234' + )); + $this->assertEquals('http://test.com/apparthotel-1234', $request->getUri()); + $this->assertEquals('/apparthotel-1234', $request->getPathInfo()); + $this->assertEquals('', $request->getQueryString()); + $this->assertEquals(80, $request->getPort()); + $this->assertEquals('test.com', $request->getHttpHost()); + $this->assertFalse($request->isSecure()); } /** @@ -1299,7 +1314,7 @@ public function getBaseUrlData() { return array( array( - '/foo%20bar', + '/foo%20bar/', array( 'SCRIPT_FILENAME' => '/home/John Doe/public_html/foo bar/app.php', 'SCRIPT_NAME' => '/foo bar/app.php', From eedf817dcc81472c1efe1c04583c345d800da31d Mon Sep 17 00:00:00 2001 From: rkerner Date: Fri, 19 Dec 2014 17:22:43 +0100 Subject: [PATCH 2/2] * fixed styleguide --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 2765c6f7db8d3..51e8f96c22eb3 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1693,7 +1693,7 @@ protected function prepareBaseUrl() return $prefix; } - if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl) . '/')) { + if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl).'/')) { // directory portion of $baseUrl matches return rtrim($prefix, '/'); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 28be099284694..109a267fd8fe6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -227,10 +227,10 @@ public function testCreate() ## assume rewrite rule: (.*) --> app/app.php ; app/ is a symlink to a symfony web/ directory $request = Request::create('http://test.com/apparthotel-1234', 'GET', array(), array(), array(), array( - 'DOCUMENT_ROOT' =>'/var/www/www.test.com', + 'DOCUMENT_ROOT' => '/var/www/www.test.com', 'SCRIPT_FILENAME' => '/var/www/www.test.com/app/app.php', 'SCRIPT_NAME' => '/app/app.php', - 'PHP_SELF' => '/app/app.php/apparthotel-1234' + 'PHP_SELF' => '/app/app.php/apparthotel-1234', )); $this->assertEquals('http://test.com/apparthotel-1234', $request->getUri()); $this->assertEquals('/apparthotel-1234', $request->getPathInfo());