diff --git a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini index dba071f..25337b3 100644 --- a/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini +++ b/administrator/components/com_jedchecker/language/en-GB/en-GB.com_jedchecker.ini @@ -92,6 +92,7 @@ COM_JEDCHECKER_LANG_KEY_NOT_ASCII="The key name is not ASCII-compatible" COM_JEDCHECKER_LANG_KEY_NOT_UPPERCASE="The key name is not uppercase" COM_JEDCHECKER_LANG_KEY_DUPLICATED="The key name was declared previously on line %d" COM_JEDCHECKER_LANG_TRANSLATION_ERROR="Invalid translation string" +COM_JEDCHECKER_LANG_INVALID_UTF8="Invalid UTF8 string" COM_JEDCHECKER_LANG_TRANSLATION_QUOTES="All translation strings should be enclosed in double quotation marks" COM_JEDCHECKER_LANG_TRANSLATION_EMPTY="Empty translation string" COM_JEDCHECKER_LANG_QQ_DEPRECATED="Usage of \"_QQ_\" is deprecated since Joomla! 3.9. Use escaped double quotes (\\\") instead" diff --git a/administrator/components/com_jedchecker/libraries/rules/language.php b/administrator/components/com_jedchecker/libraries/rules/language.php index fe9ac4b..b883617 100644 --- a/administrator/components/com_jedchecker/libraries/rules/language.php +++ b/administrator/components/com_jedchecker/libraries/rules/language.php @@ -96,6 +96,9 @@ class JedcheckerRulesLanguage extends JEDcheckerRule $nLines = count($lines); $keys = array(); + // Use mb_check_encoding (if exists) to validate UTF-8 + $mbExists = function_exists('mb_check_encoding'); + for ($lineno = 0; $lineno < $nLines; $lineno++) { $startLineno = $lineno + 1; @@ -223,6 +226,14 @@ class JedcheckerRulesLanguage extends JEDcheckerRule continue; } + // Check it's a valid UTF-8 string + $validUTF8 = $mbExists ? mb_check_encoding($value, 'UTF-8') : preg_match('//u', $value); + + if (!$validUTF8) + { + $this->report->addWarning($file, JText::_('COM_JEDCHECKER_LANG_INVALID_UTF8'), $startLineno, $line); + } + if (strlen($value) < 2 || $value[0] !== '"' || substr($value, -1) !== '"') { $this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_QUOTES'), $startLineno, $line);