Skip to content

Commit

Permalink
Improve documentNotUTF8 check in ToolsError for HTML support
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveRandom committed Sep 18, 2013
1 parent 46ed4c5 commit de3eaf1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions php/ToolsError.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,11 +1346,19 @@ function documentNotUTF8($lang)
$content = $this->lang_content;
}

$matches = array();
preg_match('!<\?xml(.+)\s?encoding=("|\')(.*)("|\')\s?\?>!U', $content, $matches);
$exprs = array(
'#<\?xml[^>]+encoding=([\'"])[Uu][Tt][Ff]-8\1#U',
'#<meta\s+(?:(?:http-equiv\s*=\s*([\'"])content-type\1\s*)|(?:content\s*=\s*([\'"])text/html\s*;.*charset\s*=\s*utf-?8.*\2\s*)){2}#Ui',
'#<meta\s+charset\s*=\s*([\'"])utf-?8\1#Ui',
);

if ( !isset($matches[3]) || strtoupper($matches[3]) != 'UTF-8') {
foreach ($exprs as $expr) {
if ( $match = preg_match($expr, $content) ) {
break;
}
}

if (!$match) {
$this->addError(array(
'value_en' => 'N/A',
'value_lang' => 'N/A',
Expand Down

0 comments on commit de3eaf1

Please sign in to comment.