Skip to content

Commit

Permalink
Fix URI RFC3986 parsing and invalid characters
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jan 2, 2025
1 parent b77529a commit 5604a26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function normalizePsr7Uri(UriInterface $uri): UriInterface
*/
public static function new(Stringable|string $uri = ''): self
{
return self::fromComponents(UriString::parse($uri));
return new self(Uri::new($uri));
}

/**
Expand Down
4 changes: 0 additions & 4 deletions HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ public static function validUrlProvider(): array
'http://login:[email protected]/',
'http://login:[email protected]/',
],
'empty string' => [
'',
'',
],
];
}

Expand Down
16 changes: 6 additions & 10 deletions Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ public static function tryNew(Stringable|string|null $uri = ''): ?self
*/
public static function new(Stringable|string $uri = ''): self
{
$uri = (string) $uri;
if ('' === $uri) {
return new self(null, null, null, null, null, '', null, null);
}

$components = UriString::parse($uri);

return new self(
Expand Down Expand Up @@ -473,16 +478,7 @@ public static function fromBaseUri(
Stringable|string $uri,
Stringable|string|null $baseUri = null
): self {
$uri = self::new($uri);
$baseUri = self::tryNew($baseUri) ?? $uri;

/** @var self $uri */
$uri = match (true) {
$baseUri->isAbsolute() => $baseUri->resolve($uri),
default => throw new SyntaxError('the URI `'.$baseUri.'` must be absolute.'),
};

return $uri;
return self::new(UriString::resolve($uri, $baseUri));
}

/**
Expand Down

0 comments on commit 5604a26

Please sign in to comment.