mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2024-12-29 04:42:36 +00:00
Check for invalid UTF8 values
This commit is contained in:
parent
9c6295231e
commit
566ce26d11
@ -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"
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user