Skip to content

Commit

Permalink
Fix path detection in Server::requestUri
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Mar 23, 2022
1 parent 6b20fa1 commit 9f9d224
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Http/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions tests/Http/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function provideRequestUri(): array
[
null,
[
'path' => '',
'path' => null,
'query' => null
]
],
Expand All @@ -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'
]
],
Expand Down

0 comments on commit 9f9d224

Please sign in to comment.