diff --git a/src/Http/Server.php b/src/Http/Server.php index d41827305a..d343254ea2 100644 --- a/src/Http/Server.php +++ b/src/Http/Server.php @@ -268,7 +268,14 @@ public static function port(bool $forwarded = false): int public static function requestUri(): array { $uri = static::get('REQUEST_URI', ''); - $uri = parse_url($uri); + + if (Url::isAbsolute($uri) === true) { + $uri = parse_url($uri); + } else { + // the fake domain is needed to make sure the URL parsing is + // always correct. Even if there's a colon in the path for params + $uri = parse_url('http://getkirby.com' . $uri); + } return [ 'path' => $uri['path'] ?? null, diff --git a/tests/Http/ServerTest.php b/tests/Http/ServerTest.php index 259089b388..b29951f104 100644 --- a/tests/Http/ServerTest.php +++ b/tests/Http/ServerTest.php @@ -360,7 +360,7 @@ public function provideRequestUri(): array [ null, [ - 'path' => '', + 'path' => null, 'query' => null ] ], @@ -385,10 +385,24 @@ public function provideRequestUri(): array 'query' => 'foo=bar' ] ], + [ + '/foo/bar/page:2?foo=bar', + [ + 'path' => '/foo/bar/page:2', + 'query' => 'foo=bar' + ] + ], + [ + '/foo/bar/page;2?foo=bar', + [ + 'path' => '/foo/bar/page;2', + 'query' => 'foo=bar' + ] + ], [ 'index.php?foo=bar', [ - 'path' => 'index.php', + 'path' => null, 'query' => 'foo=bar' ] ],