10
10
use DOMNodeList ;
11
11
use DOMText ;
12
12
use Exception ;
13
+ use LibXMLError ;
13
14
14
15
use WMDE \VueJsTemplating \FilterExpressionParsing \FilterParser ;
15
16
use WMDE \VueJsTemplating \JsParsing \BasicJsExpressionParser ;
@@ -65,6 +66,7 @@ public function render( array $data ) {
65
66
* @return DOMDocument
66
67
*/
67
68
private function parseHtml ( $ template ) {
69
+ $ entityLoaderDisabled = libxml_disable_entity_loader ( true );
68
70
$ internalErrors = libxml_use_internal_errors ( true );
69
71
$ document = new DOMDocument ();
70
72
@@ -73,9 +75,14 @@ private function parseHtml( $template ) {
73
75
//TODO Test failure
74
76
}
75
77
78
+ /** @var LibXMLError[] $errors */
76
79
$ errors = libxml_get_errors ();
77
80
libxml_clear_errors ();
81
+
82
+ // Restore previous state
78
83
libxml_use_internal_errors ( $ internalErrors );
84
+ libxml_disable_entity_loader ( $ entityLoaderDisabled );
85
+
79
86
foreach ( $ errors as $ error ) {
80
87
//TODO html5 tags can fail parsing
81
88
//TODO Throw an exception
@@ -243,8 +250,7 @@ private function handleFor( DOMNode $node, array $data ) {
243
250
}
244
251
245
252
private function appendHTML ( DOMNode $ parent , $ source ) {
246
- $ tmpDoc = new DOMDocument ();
247
- $ tmpDoc ->loadHTML ( $ source );
253
+ $ tmpDoc = $ this ->parseHtml ( $ source );
248
254
foreach ( $ tmpDoc ->getElementsByTagName ( 'body ' )->item ( 0 )->childNodes as $ node ) {
249
255
$ node = $ parent ->ownerDocument ->importNode ( $ node , true );
250
256
$ parent ->appendChild ( $ node );
0 commit comments