mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 01:25:56 +00:00
validate URLs: convert IDN to punycode before passing URL to filter_var()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user