@@ -442,17 +442,13 @@ public function testWithFragmentThrowExceptionForInvalidFragment($query): void
442442 $ this ->uri ->withQuery ($ query );
443443 }
444444
445- public function testUtf8Host (): void
446- {
447- $ uri = (new Uri ())->withHost ($ host = '例子.例子 ' );
448- $ this ->assertSame ($ host , $ uri ->getHost ());
449- $ this ->assertSame ('// ' . $ host , (string ) $ uri );
450- }
451-
452445 public function testPercentageEncodedWillNotBeReEncoded (): void
453446 {
454- $ uri = new Uri ('https://example.com/pa<th/to/tar>get/?qu^ery=str|ing#frag%ment ' );
455- $ this ->assertSame ('https://example.com/pa%3Cth/to/tar%3Eget/?qu%5Eery=str%7Cing#frag%25ment ' , (string ) $ uri );
447+ $ uri =
new Uri (
'https://us%40er:pa%[email protected] /pa<th/to/tar>get/?qu^ery=str|ing#frag%ment ' );
448+ $ this ->assertSame (
449+ 'https://us%40er:pa%[email protected] /pa%3Cth/to/tar%3Eget/?qu%5Eery=str%7Cing#frag%25ment ' ,
450+ (string ) $ uri ,
451+ );
456452
457453 $ newUri = new Uri ((string ) $ uri );
458454 $ this ->assertSame ((string ) $ uri , (string ) $ newUri );
@@ -467,6 +463,41 @@ public function testPercentageEncodedWillNotBeReEncoded(): void
467463 $ this ->assertSame ($ fragment , $ uri ->getFragment ());
468464 }
469465
466+ public function testUtf8Host (): void
467+ {
468+ $ uri = new Uri ('https://ουτοπία.δπθ.gr/ ' );
469+ $ this ->assertSame ('ουτοπία.δπθ.gr ' , $ uri ->getHost ());
470+ $ new = $ uri ->withHost ($ host = '程式设计.com ' );
471+ $ this ->assertSame ($ host , $ new ->getHost ());
472+
473+ $ uri = (new Uri ())->withHost ($ host = '例子.例子 ' );
474+ $ this ->assertSame ($ host , $ uri ->getHost ());
475+ $ this ->assertSame ('// ' . $ host , (string ) $ uri );
476+
477+ $ uri = (new Uri ())->withHost ($ host = 'παράδειγμα.δοκιμή ' );
478+ $ this ->assertSame ($ host , $ uri ->getHost ());
479+ $ this ->assertSame ('// ' . $ host , (string ) $ uri );
480+
481+ $ uri = (new Uri ())->withHost ($ host = 'яндекс.рф ' );
482+ $ this ->assertSame ($ host , $ uri ->getHost ());
483+
484+ // "A" is a Latin letter
485+ $ uri = (new Uri ())->withHost ('яндекAс.рф ' );
486+ $ this ->assertSame ('яндекaс.рф ' , $ uri ->getHost ());
487+ }
488+
489+ public function testIPv6Host (): void
490+ {
491+ $ uri = new Uri ('https://[2a00:f48:1008::212:183:10] ' );
492+ $ this ->assertSame ('[2a00:f48:1008::212:183:10] ' , $ uri ->getHost ());
493+
494+ $ uri = new Uri ('https://[2a00:f48:1008::212:183:10]:56/path/to/target?key=value ' );
495+ $ this ->assertSame ('[2a00:f48:1008::212:183:10] ' , $ uri ->getHost ());
496+ $ this ->assertSame (56 , $ uri ->getPort ());
497+ $ this ->assertSame ('/path/to/target ' , $ uri ->getPath ());
498+ $ this ->assertSame ('key=value ' , $ uri ->getQuery ());
499+ }
500+
470501 /**
471502 * @param array $values
472503 * @return array
0 commit comments