diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index ef1a514bd..8db6ad7cc 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -626,7 +626,7 @@ function getGateway() } // Try to convert possible IDNA domain to Unicode -function convertIDNAToUnicode($unicode) +function convertIDNAToUnicode($IDNA) { if (extension_loaded('intl')) { // we try the UTS #46 standard first @@ -638,32 +638,42 @@ function convertIDNAToUnicode($unicode) // to ensure sparkasse-gießen.de is not converted into // sparkass-giessen.de but into xn--sparkasse-gieen-2ib.de // as mandated by the UTS #46 standard - $unicode = idn_to_utf8($unicode, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); + $unicode = idn_to_utf8($IDNA, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); } elseif (defined('INTL_IDNA_VARIANT_2003')) { // If conversion failed, try with the (deprecated!) IDNA 2003 variant // We have to check for its existence as support of this variant is // scheduled for removal with PHP 8.0 // see https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003 - $unicode = idn_to_utf8($unicode, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); + $unicode = idn_to_utf8($IDNA, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); } } - return $unicode; + // if the conversion failed (e.g. domain to long) return the original domain + if ($unicode == false) { + return $IDNA; + } else { + return $unicode; + } } // Convert a given (unicode) domain to IDNA ASCII -function convertUnicodeToIDNA($IDNA) +function convertUnicodeToIDNA($unicode) { if (extension_loaded('intl')) { // Be prepared that this may fail and see our comments about convertIDNAToUnicode() if (defined('INTL_IDNA_VARIANT_UTS46')) { - $IDNA = idn_to_ascii($IDNA, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); + $IDNA = idn_to_ascii($unicode, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); } elseif (defined('INTL_IDNA_VARIANT_2003')) { - $IDNA = idn_to_ascii($IDNA, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); + $IDNA = idn_to_ascii($unicode, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); } } - return $IDNA; + // if the conversion failed (e.g. domain to long) return the original domain + if ($IDNA == false) { + return $unicode; + } else { + return $IDNA; + } } // Return PID of FTL (used in settings.php) diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 7357b037c..7cd418609 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -510,14 +510,11 @@ function verify_ID_array($arr) $res['groups'] = $groups; if ($res['type'] === LISTTYPE_WHITELIST || $res['type'] === LISTTYPE_BLACKLIST) { // Convert domain name to international form - // Skip this for the root zone `.` - if ($res['domain'] != '.') { - $utf8_domain = convertIDNAToUnicode($res['domain']); + $utf8_domain = convertIDNAToUnicode($res['domain']); - // if domain and international form are different, show both - if ($res['domain'] !== $utf8_domain) { - $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; - } + // if domain and international form are different, show both + if ($res['domain'] !== $utf8_domain) { + $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; } } // Prevent domain and comment fields from returning any arbitrary javascript code which could be executed on the browser. @@ -600,10 +597,7 @@ function verify_ID_array($arr) // If not adding a RegEx.... $input = $domain; // Convert domain name to IDNA ASCII form for international domains - // Skip this for the root zone `.` - if ($domain != '.') { - $domain = convertUnicodeToIDNA($domain); - } + $domain = convertUnicodeToIDNA($domain); // convert the domain lower case and check whether it is valid $domain = strtolower($domain); $msg = '';