File tree 3 files changed +11
-7
lines changed
3 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 30
30
use function rawurldecode ;
31
31
use function rawurlencode ;
32
32
use function sprintf ;
33
+ use function str_starts_with ;
33
34
use function strtolower ;
34
35
use function strtoupper ;
35
36
@@ -300,8 +301,8 @@ public static function normalizeHost(Stringable|string|null $host): ?string
300
301
return $ host ;
301
302
}
302
303
303
- if (( $ newHost = IPv6Converter:: normalize ( $ host)) !== $ host ) {
304
- return $ newHost ;
304
+ if (str_starts_with ( $ host, ' [ ' ) ) {
305
+ return IPv6Converter:: normalize ( $ host ) ;
305
306
}
306
307
307
308
$ host = strtolower ($ host );
Original file line number Diff line number Diff line change @@ -100,8 +100,6 @@ public static function build(array $components): string
100
100
}
101
101
102
102
/**
103
- * @param Stringable|string|null $host
104
- *
105
103
* @return array{ipAddress:string|null, zoneIdentifier:string|null}
106
104
*/
107
105
private static function parse (Stringable |string |null $ host ): array
@@ -145,9 +143,14 @@ public static function isIpv6(Stringable|string|null $host): bool
145
143
146
144
public static function normalize (Stringable |string |null $ host ): ?string
147
145
{
146
+ if (null === $ host || '' === $ host ) {
147
+ return $ host ;
148
+ }
149
+
150
+ $ host = (string ) $ host ;
148
151
$ components = self ::parse ($ host );
149
152
if (null === $ components ['ipAddress ' ]) {
150
- return $ host ;
153
+ return strtolower ( $ host) ;
151
154
}
152
155
153
156
$ components ['ipAddress ' ] = strtolower ($ components ['ipAddress ' ]);
Original file line number Diff line number Diff line change @@ -298,12 +298,12 @@ public static function parseNormalized(Stringable|string $uri): array
298
298
299
299
$ host = $ components ['host ' ];
300
300
if (null !== $ host && false === filter_var ($ host , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 )) {
301
- $ host = IPv6Converter::normalize ($ host );
301
+ $ host = ( string ) IPv6Converter::normalize ($ host );
302
302
if ($ host === $ components ['host ' ]) {
303
303
$ host = (string ) preg_replace_callback (
304
304
'/%[0-9A-F]{2}/i ' ,
305
305
fn (array $ matches ): string => strtoupper ($ matches [0 ]),
306
- strtolower ($ components [ ' host ' ] )
306
+ strtolower ($ host )
307
307
);
308
308
if ($ isSupported ) {
309
309
$ idnaHost = IdnaConverter::toAscii (rawurldecode ($ components ['host ' ]));
You can’t perform that action at this time.
0 commit comments