diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index ee611e565a29..a9f5b27f4915 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -613,6 +613,20 @@ public function getRequestUri() { $uri = isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : ''; if($this->config->getSystemValue('overwritewebroot') !== '' && $this->isOverwriteCondition()) { $uri = $this->getScriptName() . substr($uri, strlen($this->server['SCRIPT_NAME'])); + } else { + $components = parse_url($uri); + if ($components === false) { + // due to https://bugs.php.net/bug.php?id=70942 we have to add a + // fake schema and host to successfully extract path, query and fragment + $components = parse_url("http://localhost$uri"); + } + $uri = $components['path']; + if (isset($components['query'])) { + $uri .= '?'.$components['query']; + } + if (isset($components['fragment'])) { + $uri .= '#'.$components['fragment']; + } } return $uri; } diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 9271fb73f2f8..3b3c127dee2b 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -16,13 +16,14 @@ use OCP\IRequest; use OCP\Security\ISecureRandom; use OCP\IConfig; +use Test\TestCase; /** * Class RequestTest * * @package OC\AppFramework\Http */ -class RequestTest extends \Test\TestCase { +class RequestTest extends TestCase { /** @var string */ protected $stream = 'fakeinput://data'; /** @var ISecureRandom | \PHPUnit_Framework_MockObject_MockObject */ @@ -1337,7 +1338,22 @@ public function pathInfoProvider() { ]; } - public function testGetRequestUriWithoutOverwrite() { + public function providesUri() { + return[ + ['/test.php', '/test.php'], + ['/remote.php/dav/files/user0/test_folder:5', '/remote.php/dav/files/user0/test_folder:5'], + ['/remote.php/dav/files/admin/welcome.txt', 'http://localhost:8080/remote.php/dav/files/admin/welcome.txt'], + ['/path?arg=value#anchor', 'http://username:password@hostname:9090/path?arg=value#anchor'], + ['/path:5?arg=value#anchor', 'http://username:password@hostname:9090/path:5?arg=value#anchor'], + ['', ''], + ['/test.php', '/test.php'], + ]; + } + + /** + * @dataProvider providesUri + */ + public function testGetRequestUriWithoutOverwrite($expectedUri, $requestUri) { $this->config ->expects($this->once()) ->method('getSystemValue') @@ -1347,7 +1363,7 @@ public function testGetRequestUriWithoutOverwrite() { $request = new Request( [ 'server' => [ - 'REQUEST_URI' => '/test.php' + 'REQUEST_URI' => $requestUri ] ], $this->secureRandom, @@ -1356,7 +1372,7 @@ public function testGetRequestUriWithoutOverwrite() { $this->stream ); - $this->assertSame('/test.php', $request->getRequestUri()); + $this->assertSame($expectedUri, $request->getRequestUri()); } public function providesGetRequestUriWithOverwriteData() {