File tree Expand file tree Collapse file tree 3 files changed +34
-7
lines changed
Expand file tree Collapse file tree 3 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -47,10 +47,6 @@ function getUrl()
4747 $ url .= "& {$ name }= {$ value }" ;
4848 }
4949
50- if (!filter_var ($ url , FILTER_VALIDATE_URL )) {
51- return 'http://doNotTryToXSS.invalid ' ;
52- }
53-
5450 return $ url ;
5551}
5652
Original file line number Diff line number Diff line change @@ -504,7 +504,7 @@ protected function buildUrl()
504504 */
505505 protected function parseUrl ($ url )
506506 {
507- $ this ->info = parse_url ($ url );
507+ $ this ->info = self :: parse ($ url );
508508
509509 if (isset ($ this ->info ['path ' ])) {
510510 $ this ->setPath ($ this ->info ['path ' ]);
@@ -610,12 +610,43 @@ private function setPath($path)
610610 }
611611 }
612612
613- private function getSuffixes ()
613+ private static function getSuffixes ()
614614 {
615615 if (self ::$ public_suffix_list === null ) {
616616 self ::$ public_suffix_list = include __DIR__ .'/../resources/public_suffix_list.php ' ;
617617 }
618618
619619 return self ::$ public_suffix_list ;
620620 }
621+
622+ /**
623+ * UTF-8 compatible parse_url
624+ * http://php.net/manual/en/function.parse-url.php#114817
625+ *
626+ * @param string $url
627+ *
628+ * @return string
629+ */
630+ private static function parse ($ url )
631+ {
632+ $ enc_url = preg_replace_callback (
633+ '%[^:/@?&=#]+%usD ' ,
634+ function ($ matches ) {
635+ return urlencode ($ matches [0 ]);
636+ },
637+ $ url
638+ );
639+
640+ $ parts = parse_url ($ enc_url );
641+
642+ if ($ parts === false ) {
643+ throw new \InvalidArgumentException ('Malformed URL: ' . $ url );
644+ }
645+
646+ foreach ($ parts as $ name => $ value ) {
647+ $ parts [$ name ] = urldecode ($ value );
648+ }
649+
650+ return $ parts ;
651+ }
621652}
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ public static function toUtf8($content, $charset)
211211 }
212212
213213 if (function_exists ('iconv ' )) {
214- return iconv ($ charset , 'UTF-8 ' , $ content );
214+ return iconv ($ charset , 'UTF-8//TRANSLIT//IGNORE ' , $ content );
215215 }
216216
217217 return $ content ;
You can’t perform that action at this time.
0 commit comments