@@ -92,7 +92,20 @@ public static function encodeUser(Stringable|string|null $component): ?string
9292 */
9393 public static function normalizeUser (Stringable |string |null $ user ): ?string
9494 {
95- return self ::encodeUser (self ::decodeUnreservedCharacters ($ user ));
95+ return self ::normalize (self ::encodeUser (self ::decodeUnreservedCharacters ($ user )));
96+ }
97+
98+ private static function normalize (?string $ component ): ?string
99+ {
100+ if (null === $ component ) {
101+ return null ;
102+ }
103+
104+ return (string ) preg_replace_callback (
105+ '/%[0-9a-f]{2}/i ' ,
106+ static fn (array $ found ) => strtoupper ($ found [0 ]),
107+ $ component
108+ );
96109 }
97110
98111 /**
@@ -126,7 +139,7 @@ public static function encodePassword(#[SensitiveParameter] Stringable|string|nu
126139 */
127140 public static function normalizePassword (#[SensitiveParameter] Stringable |string |null $ password ): ?string
128141 {
129- return self ::encodePassword (self ::decodeUnreservedCharacters ($ password ));
142+ return self ::normalize ( self :: encodePassword (self ::decodeUnreservedCharacters ($ password) ));
130143 }
131144
132145 /**
@@ -259,7 +272,7 @@ public static function decodePath(Stringable|string|null $path): ?string
259272 */
260273 public static function normalizePath (Stringable |string |null $ component ): ?string
261274 {
262- return self ::encodePath (self ::decodePath ($ component ));
275+ return self ::normalize ( self :: encodePath (self ::decodePath ($ component) ));
263276 }
264277
265278 /**
@@ -295,7 +308,7 @@ public static function decodeQuery(Stringable|string|null $path): ?string
295308 */
296309 public static function normalizeQuery (Stringable |string |null $ query ): ?string
297310 {
298- return self ::encodeQueryOrFragment (self ::decodeQuery ($ query ));
311+ return self ::normalize ( self :: encodeQueryOrFragment (self ::decodeQuery ($ query) ));
299312 }
300313
301314 /**
@@ -325,7 +338,7 @@ public static function decodeFragment(Stringable|string|null $path): ?string
325338 */
326339 public static function normalizeFragment (Stringable |string |null $ fragment ): ?string
327340 {
328- return self ::encodeQueryOrFragment (self ::decodeFragment ($ fragment ));
341+ return self ::normalize ( self :: encodeQueryOrFragment (self ::decodeFragment ($ fragment) ));
329342 }
330343
331344 /**
0 commit comments