1010use DOMNodeList ;
1111use DOMText ;
1212use Exception ;
13+ use LibXMLError ;
1314
1415use WMDE \VueJsTemplating \FilterExpressionParsing \FilterParser ;
1516use WMDE \VueJsTemplating \JsParsing \BasicJsExpressionParser ;
@@ -65,6 +66,7 @@ public function render( array $data ) {
6566 * @return DOMDocument
6667 */
6768 private function parseHtml ( $ template ) {
69+ $ entityLoaderDisabled = libxml_disable_entity_loader ( true );
6870 $ internalErrors = libxml_use_internal_errors ( true );
6971 $ document = new DOMDocument ();
7072
@@ -73,9 +75,14 @@ private function parseHtml( $template ) {
7375 //TODO Test failure
7476 }
7577
78+ /** @var LibXMLError[] $errors */
7679 $ errors = libxml_get_errors ();
7780 libxml_clear_errors ();
81+
82+ // Restore previous state
7883 libxml_use_internal_errors ( $ internalErrors );
84+ libxml_disable_entity_loader ( $ entityLoaderDisabled );
85+
7986 foreach ( $ errors as $ error ) {
8087 //TODO html5 tags can fail parsing
8188 //TODO Throw an exception
@@ -243,8 +250,7 @@ private function handleFor( DOMNode $node, array $data ) {
243250 }
244251
245252 private function appendHTML ( DOMNode $ parent , $ source ) {
246- $ tmpDoc = new DOMDocument ();
247- $ tmpDoc ->loadHTML ( $ source );
253+ $ tmpDoc = $ this ->parseHtml ( $ source );
248254 foreach ( $ tmpDoc ->getElementsByTagName ( 'body ' )->item ( 0 )->childNodes as $ node ) {
249255 $ node = $ parent ->ownerDocument ->importNode ( $ node , true );
250256 $ parent ->appendChild ( $ node );
0 commit comments