@@ -451,7 +451,7 @@ public function __toString()
451
451
452
452
453
453
/**
454
- * Similar to rawurldecode, but preserve reserved chars encoded.
454
+ * Similar to rawurldecode, but preserves reserved chars encoded.
455
455
* @param string to decode
456
456
* @param string reserved characters
457
457
* @return string
@@ -461,14 +461,11 @@ public static function unescape($s, $reserved = '%;/?:@&=+$,')
461
461
// reserved (@see RFC 2396) = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ","
462
462
// within a path segment, the characters "/", ";", "=", "?" are reserved
463
463
// within a query component, the characters ";", "/", "?", ":", "@", "&", "=", "+", ",", "$" are reserved.
464
- preg_match_all ('#(?<=%)[a-f0-9][a-f0-9]#i ' , $ s , $ matches , PREG_OFFSET_CAPTURE | PREG_SET_ORDER );
465
- foreach (array_reverse ($ matches ) as $ match ) {
466
- $ ch = chr (hexdec ($ match [0 ][0 ]));
467
- if (strpos ($ reserved , $ ch ) === FALSE ) {
468
- $ s = substr_replace ($ s , $ ch , $ match [0 ][1 ] - 1 , 3 );
469
- }
470
- }
471
- return $ s ;
464
+ return $ reserved === '' ? rawurldecode ($ s ) : preg_replace_callback (
465
+ '#(?:%(?! ' . implode ('| ' , str_split (bin2hex ($ reserved ), 2 )) . ')[0-9a-f]{2})++#i ' ,
466
+ function ($ m ) { return rawurldecode ($ m [0 ]); },
467
+ $ s
468
+ );
472
469
}
473
470
474
471
}
0 commit comments