|
76 | 76 | use function strpos; |
77 | 77 | use function strspn; |
78 | 78 | use function strtolower; |
79 | | -use function strtoupper; |
80 | 79 | use function substr; |
81 | 80 | use function trim; |
82 | 81 |
|
@@ -382,24 +381,19 @@ private function formatHost(?string $host): ?string |
382 | 381 | private function formatRegisteredName(string $host): string |
383 | 382 | { |
384 | 383 | $formattedHost = rawurldecode($host); |
385 | | - if ($formattedHost !== $host) { |
386 | | - |
387 | | - if (IdnaConverter::toAscii($formattedHost)->hasErrors()) { |
388 | | - throw new SyntaxError('The host `'.$host.'` is invalid : the registered name contains invalid characters.'); |
389 | | - } |
| 384 | + if ($formattedHost === $host) { |
| 385 | + return match (1) { |
| 386 | + preg_match(self::REGEXP_HOST_REGNAME, $formattedHost) => $formattedHost, |
| 387 | + preg_match(self::REGEXP_HOST_GEN_DELIMS, $formattedHost) => throw new SyntaxError('The host `'.$host.'` is invalid : a registered name cannot contain URI delimiters or spaces.'), |
| 388 | + default => IdnaConverter::toAsciiOrFail($host), |
| 389 | + }; |
| 390 | + } |
390 | 391 |
|
391 | | - return (string) preg_replace_callback( |
392 | | - '/%[0-9A-F]{2}/i', |
393 | | - fn (array $matches) => strtoupper($matches[0]), |
394 | | - strtolower($host) |
395 | | - ); |
| 392 | + if (IdnaConverter::toAscii($formattedHost)->hasErrors()) { |
| 393 | + throw new SyntaxError('The host `'.$host.'` is invalid : the registered name contains invalid characters.'); |
396 | 394 | } |
397 | 395 |
|
398 | | - return match (1) { |
399 | | - preg_match(self::REGEXP_HOST_REGNAME, $formattedHost) => $formattedHost, |
400 | | - preg_match(self::REGEXP_HOST_GEN_DELIMS, $formattedHost) => throw new SyntaxError('The host `'.$host.'` is invalid : a registered name cannot contain URI delimiters or spaces.'), |
401 | | - default => IdnaConverter::toAsciiOrFail($host), |
402 | | - }; |
| 396 | + return (string) Encoder::normalizeHost($host); |
403 | 397 | } |
404 | 398 |
|
405 | 399 | /** |
@@ -1185,7 +1179,6 @@ public function toDisplayString(): string |
1185 | 1179 | { |
1186 | 1180 | $components = $this->toComponents(); |
1187 | 1181 |
|
1188 | | - |
1189 | 1182 | unset($components['port']); |
1190 | 1183 | if (null !== $components['host']) { |
1191 | 1184 | $components['host'] = IdnaConverter::toUnicode($components['host'])->domain(); |
|
0 commit comments