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

Commit d7c1c05

Browse files
committed
For consistency we use the Idna package with WhatWgUrl
1 parent 259609b commit d7c1c05

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/WhatWg/Url.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
use Bakame\Aide\Uri\UrlValidationErrorCollector;
1717
use Exception;
18-
use League\Uri\UriString;
1918
use ReflectionClass;
2019
use Rowbot\Idna\Idna;
20+
use Rowbot\URL\Component\Host\StringHost;
2121
use Rowbot\URL\URL as WhatWgURL;
22+
use Rowbot\URL\URLRecord;
2223
use SensitiveParameter;
2324
use Uri\UriComparisonMode;
2425

@@ -294,12 +295,19 @@ public function toUnicodeString(): string
294295
}
295296

296297
$unicodeHost = $this->getUnicodeHost();
297-
$this->urlUnicodeString = $this->getAsciiHost() === $unicodeHost
298-
? $this->url->href
299-
: UriString::build([
300-
...UriString::parse($this->url->href),
301-
...['host' => $unicodeHost],
302-
]);
298+
if (null === $unicodeHost || $this->getAsciiHost() === $unicodeHost) {
299+
$this->urlUnicodeString = $this->url->href;
300+
301+
return $this->urlUnicodeString;
302+
}
303+
304+
//We use the URLRecord to stay fully compliant with the WHATAG specification
305+
//We are forced tu use reflection as we can not access the URLRecord directly
306+
$refl = new ReflectionClass(WhatWgURL::class);
307+
/** @var URLRecord $urlRecord */
308+
$urlRecord = $refl->getProperty('url')->getValue($this->url);
309+
$urlRecord->host = new StringHost($unicodeHost);
310+
$this->urlUnicodeString = $urlRecord->serializeURL();
303311

304312
return $this->urlUnicodeString;
305313
}

0 commit comments

Comments
 (0)