Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- _Scheme less_ urls now keep their leading `//` when converted to strings

### Fixed

- Url parsing idempotency with partially encoded characters

## 5.3.0 - 2026-05-14

### Changed
Expand Down
9 changes: 7 additions & 2 deletions src/Authority/UserInformation/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public static function none(): self
*/
public static function parsed(Uri|Concrete $parsed): self
{
/** @psalm-suppress ImpureMethodCall */
$password = $parsed->getPassword();
if ($parsed instanceof Uri) {
/** @psalm-suppress ImpureMethodCall */
$password = $parsed->getRawPassword();
} else {
/** @psalm-suppress ImpureMethodCall */
$password = $parsed->getPassword();
}

return match ($password) {
null => self::none(),
Expand Down
9 changes: 7 additions & 2 deletions src/Authority/UserInformation/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ public static function none(): self
*/
public static function parsed(Uri|Concrete $parsed): self
{
/** @psalm-suppress ImpureMethodCall */
$user = $parsed->getUsername();
if ($parsed instanceof Uri) {
/** @psalm-suppress ImpureMethodCall */
$user = $parsed->getRawUsername();
} else {
/** @psalm-suppress ImpureMethodCall */
$user = $parsed->getUsername();
}

return match ($user) {
null => self::none(),
Expand Down
9 changes: 7 additions & 2 deletions src/Fragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ public static function none(): self
*/
public static function parsed(Uri|Concrete $parsed): self
{
/** @psalm-suppress ImpureMethodCall */
$fragment = $parsed->getFragment();
if ($parsed instanceof Uri) {
/** @psalm-suppress ImpureMethodCall */
$fragment = $parsed->getRawFragment();
} else {
/** @psalm-suppress ImpureMethodCall */
$fragment = $parsed->getFragment();
}

return match ($fragment) {
null => self::none(),
Expand Down
9 changes: 7 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ public static function none(): self
*/
public static function parsed(Uri|Concrete $parsed): self
{
/** @psalm-suppress ImpureMethodCall */
$query = $parsed->getQuery();
if ($parsed instanceof Uri) {
/** @psalm-suppress ImpureMethodCall */
$query = $parsed->getRawQuery();
} else {
/** @psalm-suppress ImpureMethodCall */
$query = $parsed->getQuery();
}

return match ($query) {
null => self::none(),
Expand Down
2 changes: 1 addition & 1 deletion src/Scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function parsed(
#[\SensitiveParameter] string $origin,
): self {
/** @psalm-suppress ImpureMethodCall */
$scheme = $parsed->getScheme();
$scheme = $parsed->getRawScheme();

return match ($scheme) {
null => match (\str_starts_with($origin, '//')) {
Expand Down
8 changes: 8 additions & 0 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ public function testSchemeLessUrls(): BlackBox\Proof
});
}

public function testParsingIdempotencyOfPartiallyEncodedUrls()
{
$this->assertSame(
'http://h.tld/a%20b?x=%2e',
Url::of(Url::of('http://h.tld/a b?x=%2e')->toString())->toString(),
);
}

public static function cases(): array
{
return [
Expand Down
Loading