Skip to content

Commit 5d0b918

Browse files
committed
Handle CDATA lookalike comment types
1 parent 9cbc3bc commit 5d0b918

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,21 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
190190
break;
191191

192192
case '#comment':
193+
switch ( $processor->get_comment_type() ) {
194+
case WP_HTML_Processor::COMMENT_AS_ABRUPTLY_CLOSED_COMMENT:
195+
case WP_HTML_Processor::COMMENT_AS_HTML_COMMENT:
196+
$commentTextContent = $processor->get_modifiable_text();
197+
break;
198+
199+
case WP_HTML_Processor::COMMENT_AS_CDATA_LOOKALIKE:
200+
$commentTextContent = "[CDATA[{$processor->get_modifiable_text()}]]";
201+
break;
202+
203+
default:
204+
throw new Exception( "Unhandled comment type for tree construction: {$processor->get_comment_type()}" );
205+
}
193206
// Comments must be "<" then "!-- " then the data then " -->".
194-
$output .= str_repeat( $indent, $indent_level ) . "<!-- {$processor->get_modifiable_text()} -->\n";
207+
$output .= str_repeat( $indent, $indent_level ) . "<!-- {$commentTextContent} -->\n";
195208
break;
196209

197210
case '#doctype':

0 commit comments

Comments
 (0)