Skip to content

Commit 39dffd7

Browse files
committed
Normalize host to lowercase
1 parent a1bf717 commit 39dffd7

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Diff for: interfaces/UriString.php

+16-14
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,22 @@ public static function parseNormalized(Stringable|string $uri): array
296296
static $isSupported = null;
297297
$isSupported ??= (function_exists('\idn_to_ascii') && defined('\INTL_IDNA_VARIANT_UTS46'));
298298

299-
if (null !== $components['host'] &&
300-
false === filter_var($components['host'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
301-
!IPv6Converter::isIpv6($components['host'])
302-
) {
303-
$decodedHost = rawurldecode($components['host']);
304-
$components['host'] = (string) preg_replace_callback(
305-
'/%[0-9A-F]{2}/i',
306-
fn (array $matches): string => strtoupper($matches[0]),
307-
strtolower($components['host'])
308-
);
309-
if ($isSupported) {
310-
$host = IdnaConverter::toAscii($decodedHost);
311-
if (!$host->hasErrors()) {
312-
$components['host'] = $host->domain();
299+
if (null !== $components['host'] && false === filter_var($components['host'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
300+
// if host is IPv6 it should be lowercased according to
301+
// https://www.rfc-editor.org/rfc/rfc5952#section-4.3
302+
$components['host'] = strtolower($components['host']);
303+
if (!IPv6Converter::isIpv6($components['host'])) {
304+
$decodedHost = rawurldecode($components['host']);
305+
$components['host'] = (string) preg_replace_callback(
306+
'/%[0-9A-F]{2}/i',
307+
fn (array $matches): string => strtoupper($matches[0]),
308+
$components['host']
309+
);
310+
if ($isSupported) {
311+
$host = IdnaConverter::toAscii($decodedHost);
312+
if (!$host->hasErrors()) {
313+
$components['host'] = $host->domain();
314+
}
313315
}
314316
}
315317
}

0 commit comments

Comments
 (0)