Skip to content

Commit

Permalink
Fix new Uri() for relative URLs with param colon
Browse files Browse the repository at this point in the history
Fixes #6331
  • Loading branch information
distantnative committed Jul 22, 2024
1 parent 744a004 commit e23a3a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/Http/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,7 @@ protected function detectPortInHost(string|null $host = null): array
*/
protected function detectRequestUri(string|null $requestUri = null): Uri
{
// make sure the URL parser works properly when there's a
// colon in the request URI but the URI is relative
if (Url::isAbsolute($requestUri) === false) {
$requestUri = 'https://getkirby.com' . $requestUri;
}

$uri = new Uri($requestUri);
$uri = new Uri($requestUri ?? '');

// create the URI object as a combination of base uri parts
// and the parts from REQUEST_URI
Expand Down
11 changes: 10 additions & 1 deletion src/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ class Uri
public function __construct(array|string $props = [], array $inject = [])
{
if (is_string($props) === true) {
$props = parse_url($props);
// make sure the URL parser works properly when there's a
// colon in the string but the string is a relative URL
if (Url::isAbsolute($props) === false) {
$props = 'https://getkirby.com/' . $props;
$props = parse_url($props);
unset($props['scheme'], $props['host']);
} else {
$props = parse_url($props);
}

$props['username'] = $props['user'] ?? null;
$props['password'] = $props['pass'] ?? null;

Expand Down

0 comments on commit e23a3a8

Please sign in to comment.