Skip to content

Commit 3308e15

Browse files
committed
Simplify Host normalization
1 parent fa3471f commit 3308e15

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

interfaces/UriString.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use League\Uri\Exceptions\MissingFeature;
1818
use League\Uri\Exceptions\SyntaxError;
1919
use League\Uri\Idna\Converter as IdnaConverter;
20-
use League\Uri\IPv4\Converter as Ipv4Converter;
2120
use League\Uri\IPv6\Converter as IPv6Converter;
2221
use Stringable;
2322

@@ -40,6 +39,7 @@
4039
use function substr;
4140
use function uksort;
4241

42+
use const FILTER_FLAG_IPV4;
4343
use const FILTER_FLAG_IPV6;
4444
use const FILTER_VALIDATE_IP;
4545
use const PREG_SPLIT_NO_EMPTY;
@@ -289,8 +289,8 @@ public static function normalize(Stringable|string $uri): string
289289
}
290290

291291
if (null !== $components['host'] &&
292-
!IPv6Converter::isIpv6($components['host']) &&
293-
!Ipv4Converter::fromEnvironment()->isIpv4($components['host'])
292+
false === filter_var($components['host'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
293+
!IPv6Converter::isIpv6($components['host'])
294294
) {
295295
$components['host'] = IdnaConverter::toUnicode($components['host'])->domain();
296296
}
@@ -323,8 +323,8 @@ public static function normalizeAuthority(Stringable|string $authority): string
323323
{
324324
$components = UriString::parseAuthority($authority);
325325
if (null !== $components['host'] &&
326-
!IPv6Converter::isIpv6($components['host']) &&
327-
!Ipv4Converter::fromEnvironment()->isIpv4($components['host'])
326+
false === filter_var($components['host'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) &&
327+
!IPv6Converter::isIpv6($components['host'])
328328
) {
329329
$components['host'] = IdnaConverter::toUnicode((string) $components['host'])->domain();
330330
}

0 commit comments

Comments
 (0)