@@ -133,7 +133,8 @@ public function enterHtmlText(?ElementNode $node): void
133133 $ this ->subState = match (true ) {
134134 $ name === 'style ' => self ::Css,
135135 self ::isJSScript ($ node ) => self ::JavaScript,
136- default => self ::HtmlText,
136+ self ::isHtmlScript ($ node ) => self ::HtmlText,
137+ default => self ::Text,
137138 };
138139 } else {
139140 $ this ->state = self ::HtmlText;
@@ -204,6 +205,7 @@ public function escape(string $str): string
204205 self ::HtmlComment => 'LR\Filters::escapeHtmlComment( ' . $ str . ') ' ,
205206 self ::HtmlBogusTag => 'LR\Filters::escapeHtml( ' . $ str . ') ' ,
206207 self ::HtmlRawText => match ($ this ->subState ) {
208+ self ::Text => 'LR\Filters::convertJSToHtmlRawText( ' . $ str . ') ' , // sanitization, escaping is not possible
207209 self ::HtmlText => 'LR\Filters::escapeHtmlRawTextHtml( ' . $ str . ') ' ,
208210 self ::JavaScript => 'LR\Filters::escapeJs( ' . $ str . ') ' ,
209211 self ::Css => 'LR\Filters::escapeCss( ' . $ str . ') ' ,
@@ -261,4 +263,13 @@ public static function isJSScript(ElementNode $el): bool
261263 && ($ type === true || $ type === null || $ type === ''
262264 || is_string ($ type ) && preg_match ('#((application|text)/(((x-)?java|ecma|j|live)script|json)|text/plain|module|importmap)$#Ai ' , $ type ));
263265 }
266+
267+
268+ private static function isHtmlScript (ElementNode $ el ): bool
269+ {
270+ $ type = $ el ->getAttribute ('type ' );
271+ return strcasecmp ($ el ->name , 'script ' ) === 0
272+ && is_string ($ type ) && preg_match ('#text/((x-)?template|html)$#Ai ' , $ type );
273+
274+ }
264275}
0 commit comments