@@ -590,8 +590,25 @@ protected function diffCells($oldCell, $newCell, $usingExtraRow = false)
590590
591591 protected function buildTableDoms ()
592592 {
593- $ this ->oldTable = $ this ->parseTableStructure (mb_convert_encoding ($ this ->oldText , 'HTML-ENTITIES ' , 'UTF-8 ' ));
594- $ this ->newTable = $ this ->parseTableStructure (mb_convert_encoding ($ this ->newText , 'HTML-ENTITIES ' , 'UTF-8 ' ));
593+ $ this ->oldTable = $ this ->parseTableStructure ($ this ->oldText );
594+ $ this ->newTable = $ this ->parseTableStructure ($ this ->newText );
595+ }
596+
597+ /**
598+ * @param string $text
599+ *
600+ * @return \DOMDocument
601+ */
602+ protected function createDocumentWithHtml ($ text )
603+ {
604+ $ dom = new \DOMDocument ();
605+ $ dom ->loadHTML (mb_convert_encoding (
606+ $ this ->purifier ->purify (mb_convert_encoding ($ text , $ this ->encoding , mb_detect_encoding ($ text ))),
607+ 'HTML-ENTITIES ' ,
608+ $ this ->encoding
609+ ));
610+
611+ return $ dom ;
595612 }
596613
597614 /**
@@ -601,8 +618,7 @@ protected function buildTableDoms()
601618 */
602619 protected function parseTableStructure ($ text )
603620 {
604- $ dom = new \DOMDocument ();
605- $ dom ->loadHTML ($ text );
621+ $ dom = $ this ->createDocumentWithHtml ($ text );
606622
607623 $ tableNode = $ dom ->getElementsByTagName ('table ' )->item (0 );
608624
@@ -692,8 +708,7 @@ protected function setInnerHtml($node, $html)
692708 $ html = '<span class="empty"></span> ' ;
693709 }
694710
695- $ doc = new \DOMDocument ();
696- $ doc ->loadHTML (mb_convert_encoding ($ this ->purifier ->purify ($ html ), 'HTML-ENTITIES ' , 'UTF-8 ' ));
711+ $ doc = $ this ->createDocumentWithHtml ($ html );
697712 $ fragment = $ node ->ownerDocument ->createDocumentFragment ();
698713 $ root = $ doc ->getElementsByTagName ('body ' )->item (0 );
699714 foreach ($ root ->childNodes as $ child ) {
0 commit comments