Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.

Commit 89cd194

Browse files
authored
Merge pull request #4 from bakame-php/feature/resolve-consistency
Adding softError parameter to Url::resolve method
2 parents b6c5af2 + bc6ef78 commit 89cd194

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/WhatWg/Url.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ public function toUnicodeString(): string
280280
}
281281

282282
/**
283+
* @param array<int, UrlValidationError> $softErrors
284+
*
283285
* @throws InvalidUrlException
284286
*/
285-
public function resolve(string $uri): self
287+
public function resolve(string $uri, array &$softErrors = []): self
286288
{
287-
return new self($uri, $this->url->href);
289+
return new self($uri, $this->url->href, $softErrors);
288290
}
289291

290292
/**

tests/WhatWg/UrlTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,17 @@ public function it_return_the_same_instance_if_nothing_is_changed(): void
233233
self::assertTrue($urlBis->equals($url));
234234
self::assertSame($urlBis, $url);
235235
}
236+
237+
#[Test]
238+
public function it_will_return_soft_errors_when_uri_is_resolved_with_errors(): void
239+
{
240+
$softErrors = [];
241+
$url = new Url("ftp://example.com");
242+
$urlBis = $url->resolve("//user:p%61ss@example.org/💩", $softErrors);
243+
244+
self::assertSame('ftp://user:p%61ss@example.org/%F0%9F%92%A9', $urlBis->toUnicodeString());
245+
self::assertNotEmpty($softErrors);
246+
self::assertInstanceOf(UrlValidationError::class, $softErrors[0]);
247+
self::assertSame(UrlValidationErrorType::InvalidCredentials, $softErrors[0]->type);
248+
}
236249
}

0 commit comments

Comments
 (0)