validate URLs: convert IDN to punycode before passing URL to filter_var()

master
Andrew Dolgov 4 years ago
parent 6811d0bde2
commit a897c4165b

@ -69,6 +69,13 @@ class UrlHelper {
$tokens['path'] = implode("/", array_map("rawurlencode", explode("/", $tokens['path'])));
}
//convert IDNA hostname to punycode if possible
if (function_exists("idn_to_ascii")) {
if (mb_detect_encoding($tokens['host']) != 'ASCII') {
$tokens['host'] = idn_to_ascii($tokens['host']);
}
}
$url = self::build_url($tokens);
if (filter_var($url, FILTER_VALIDATE_URL) === false)
@ -82,14 +89,6 @@ class UrlHelper {
return false;
}
//convert IDNA hostname to punycode if possible
if (function_exists("idn_to_ascii")) {
if (mb_detect_encoding($tokens['host']) != 'ASCII') {
$tokens['host'] = idn_to_ascii($tokens['host']);
$url = self::build_url($tokens);
}
}
return $url;
}

Loading…
Cancel
Save