From 6e219ec6544bf3ccfe2c3ded2b3b3d167213aeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 27 Jul 2017 18:04:52 +0200 Subject: [PATCH] Add more tests and fix crazy php bugs - https://bugs.php.net/bug.php?id=70942 --- lib/private/AppFramework/Http/Request.php | 5 +++++ tests/lib/AppFramework/Http/RequestTest.php | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index 5bf77c8749a0..949136a5136a 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -603,6 +603,11 @@ public function getRequestUri() { $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']; diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 882fb7b2efc1..22556bcace9b 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -1266,7 +1266,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') @@ -1276,7 +1291,7 @@ public function testGetRequestUriWithoutOverwrite() { $request = new Request( [ 'server' => [ - 'REQUEST_URI' => '/test.php' + 'REQUEST_URI' => $requestUri ] ], $this->secureRandom, @@ -1285,7 +1300,7 @@ public function testGetRequestUriWithoutOverwrite() { $this->stream ); - $this->assertSame('/test.php', $request->getRequestUri()); + $this->assertSame($expectedUri, $request->getRequestUri()); } public function providesGetRequestUriWithOverwriteData() {