Commit 2b46250e authored by Son Nguyen's avatar Son Nguyen

Bug 1582778: Allow UTF-8 characters when preparing embedded images

Change-Id: I01ab74991240e8b4da9136c6c06756a5916cab53
behatnotneeded: manual tests is enough
parent d20e2988
...@@ -37,7 +37,10 @@ class EmbeddedImage { ...@@ -37,7 +37,10 @@ class EmbeddedImage {
$dom = new DOMDocument(); $dom = new DOMDocument();
$dom->encoding = 'utf-8'; $dom->encoding = 'utf-8';
$oldval = libxml_use_internal_errors(true); $oldval = libxml_use_internal_errors(true);
$success = $dom->loadHTML(utf8_decode($fieldvalue)); $tmpstr = (mb_detect_encoding($fieldvalue, 'auto') == 'UTF-8')
? '<?xml version="1.0" encoding="utf-8"?>' . $fieldvalue
: $fieldvalue;
$success = $dom->loadHTML($tmpstr);
libxml_use_internal_errors($oldval); libxml_use_internal_errors($oldval);
if ($success) { if ($success) {
$publicimages = array(); $publicimages = array();
...@@ -118,10 +121,12 @@ class EmbeddedImage { ...@@ -118,10 +121,12 @@ class EmbeddedImage {
// we only want the fragments inside the body tag created by new DOMDocument // we only want the fragments inside the body tag created by new DOMDocument
$childnodes = $dom->getElementsByTagName('body')->item(0)->childNodes; $childnodes = $dom->getElementsByTagName('body')->item(0)->childNodes;
$dummydom = new DOMDocument(); $dummydom = new DOMDocument();
$dummydom->loadHTML('<?xml version="1.0" encoding="utf-8"?><div></div>');
$dummydiv = $dummydom->getElementsByTagName('div')->item(0);
foreach ($childnodes as $child) { foreach ($childnodes as $child) {
$dummydom->appendChild($dummydom->importNode($child, true)); $dummydiv->appendChild($dummydom->importNode($child, true));
} }
$fieldvalue = html_entity_decode($dummydom->saveHTML(), ENT_QUOTES, 'UTF-8'); $fieldvalue = substr($dummydom->saveHTML($dummydom->getElementsByTagName('div')->item(0)), strlen('<div>'), -strlen('</div>'));
return $fieldvalue; return $fieldvalue;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment