diff options
author | Andrew Dolgov <[email protected]> | 2020-09-22 15:32:22 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2020-09-22 15:32:22 +0300 |
commit | a897c4165bebf975129edfb75ba3878f1deab9ec (patch) | |
tree | 53ff5b91aee4352abf5ffcc1c35bc0127ab4a035 | |
parent | 6811d0bde220d7632b9d6a7fa4f4931cc96324c8 (diff) |
validate URLs: convert IDN to punycode before passing URL to filter_var()
-rw-r--r-- | classes/urlhelper.php | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/classes/urlhelper.php b/classes/urlhelper.php index 29c81e760..c8e87c8ae 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -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; } |