<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[58859] trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php: HTML API: Use full parser in html5lib tests.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/58859">58859</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/58859","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dmsnell</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-08-06 22:05:47 +0000 (Tue, 06 Aug 2024)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>HTML API: Use full parser in html5lib tests.

Previously the `html5lib` tests have only run in the fragment parser mode,
assuming IN BODY context. This limited the number of tests which could run
and was a result of the HTML Processor only supporting the IN BODY fragment
parser. In <a href="https://core.trac.wordpress.org/changeset/58836">[58836]</a>, however, a full parser was added to the HTML Processor.

In this patch the full parser is utilized in order to run more of the
previously-skipped tests, asserting more behaviors in the HTML parsing.

Developed in https://github.com/wordpress/wordpress-develop/pull/7117
Discussed in https://core.trac.wordpress.org/ticket/61646

Props: dmsnell, jonsurrell.
See <a href="https://core.trac.wordpress.org/ticket/61646">#61646</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestshtmlapiwpHtmlProcessorHtml5libphp">trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestshtmlapiwpHtmlProcessorHtml5libphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php    2024-08-06 20:41:58 UTC (rev 58858)
+++ trunk/tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php      2024-08-06 22:05:47 UTC (rev 58859)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,38 +22,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_HtmlApi_Html5lib extends WP_UnitTestCase {
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * The HTML Processor only accepts HTML in document <body>.
-        * Do not run tests that look for anything in document <head>.
-        */
-       const SKIP_HEAD_TESTS = true;
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * Skip specific tests that may not be supported or have known issues.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        const SKIP_TESTS = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'adoption01/line0046' => 'Unimplemented: Reconstruction of active formatting elements.',
-               'adoption01/line0159' => 'Unimplemented: Reconstruction of active formatting elements.',
-               'adoption01/line0318' => 'Unimplemented: Reconstruction of active formatting elements.',
-               'template/line0885'   => 'Unimplemented: no parsing of attributes on context node.',
-               'tests1/line0720'     => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests15/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests15/line0022'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests15/line0068'    => 'Unimplemented: no support outside of IN BODY yet.',
-               'tests2/line0650'     => 'Whitespace only test never enters "in body" parsing mode.',
-               'tests19/line0965'    => 'Unimplemented: no support outside of IN BODY yet.',
-               'tests23/line0001'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests23/line0041'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests23/line0069'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests23/line0101'    => 'Unimplemented: Reconstruction of active formatting elements.',
-               'tests26/line0263'    => 'Bug: An active formatting element should be created for a trailing text node.',
-               'webkit01/line0231'   => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
-               'webkit02/line0013'   => "Asserting behavior with scripting flag enabled, which this parser doesn't support.",
-               'webkit01/line0300'   => 'Unimplemented: no support outside of IN BODY yet.',
-               'webkit01/line0310'   => 'Unimplemented: no support outside of IN BODY yet.',
-               'webkit01/line0336'   => 'Unimplemented: no support outside of IN BODY yet.',
-               'webkit01/line0349'   => 'Unimplemented: no support outside of IN BODY yet.',
-               'webkit01/line0362'   => 'Unimplemented: no support outside of IN BODY yet.',
-               'webkit01/line0375'   => 'Unimplemented: no support outside of IN BODY yet.',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         'comments01/line0155'    => 'Unimplemented: Need to access raw comment text on non-normative comments.',
+               'comments01/line0169'    => 'Unimplemented: Need to access raw comment text on non-normative comments.',
+               'html5test-com/line0129' => 'Unimplemented: Need to access raw comment text on non-normative comments.',
+               'noscript01/line0014'    => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests1/line0692'        => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly',
+               'tests14/line0022'       => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests14/line0055'       => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests19/line0965'       => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly.',
+               'tests19/line1079'       => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests2/line0207'        => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests2/line0686'        => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests2/line0709'        => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
+               'tests5/line0013'        => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly.',
+               'tests5/line0077'        => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly.',
+               'tests5/line0091'        => 'Bug: Mixed whitespace, non-whitespace text in head not split correctly',
+               'webkit01/line0231'      => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
</ins><span class="cx" style="display: block; padding: 0 10px">         );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,14 +55,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $html             Given test HTML.
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $expected_tree    Tree structure of parsed HTML.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_parse( $fragment_context, $html, $expected_tree ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_parse( ?string $fragment_context, string $html, string $expected_tree ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $processed_tree = self::build_tree_representation( $fragment_context, $html );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( null === $processed_tree ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->markTestSkipped( 'Test includes unsupported markup.' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $fragment_detail = $fragment_context ? " in context <{$fragment_context}>" : '';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertSame( $expected_tree, $processed_tree, "HTML was not processed correctly:\n{$html}" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * The HTML processor does not produce html, head, body tags if the processor does not reach them.
+                * HTML tree construction will always produce these tags, the HTML API does not at this time.
+                */
+               $auto_generated_html_head_body = "<html>\n  <head>\n  <body>\n\n";
+               $auto_generated_head_body      = "  <head>\n  <body>\n\n";
+               $auto_generated_body           = "  <body>\n\n";
+               if ( str_ends_with( $expected_tree, $auto_generated_html_head_body ) && ! str_ends_with( $processed_tree, $auto_generated_html_head_body ) ) {
+                       if ( str_ends_with( $processed_tree, "<html>\n  <head>\n\n" ) ) {
+                               $processed_tree = substr_replace( $processed_tree, "  <body>\n\n", -1 );
+                       } elseif ( str_ends_with( $processed_tree, "<html>\n\n" ) ) {
+                               $processed_tree = substr_replace( $processed_tree, "  <head>\n  <body>\n\n", -1 );
+                       } else {
+                               $processed_tree = substr_replace( $processed_tree, $auto_generated_html_head_body, -1 );
+                       }
+               } elseif ( str_ends_with( $expected_tree, $auto_generated_head_body ) && ! str_ends_with( $processed_tree, $auto_generated_head_body ) ) {
+                       if ( str_ends_with( $processed_tree, "<head>\n\n" ) ) {
+                               $processed_tree = substr_replace( $processed_tree, "  <body>\n\n", -1 );
+                       } else {
+                               $processed_tree = substr_replace( $processed_tree, $auto_generated_head_body, -1 );
+                       }
+               } elseif ( str_ends_with( $expected_tree, $auto_generated_body ) && ! str_ends_with( $processed_tree, $auto_generated_body ) ) {
+                       $processed_tree = substr_replace( $processed_tree, $auto_generated_body, -1 );
+               }
+
+               $this->assertSame( $expected_tree, $processed_tree, "HTML was not processed correctly{$fragment_detail}:\n{$html}" );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,7 +113,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                $line       = str_pad( strval( $test[0] ), 4, '0', STR_PAD_LEFT );
</span><span class="cx" style="display: block; padding: 0 10px">                                $test_name  = "{$test_suite}/line{$line}";
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( self::should_skip_test( $test_name, $test[3] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $test_context_element = $test[1];
+
+                               if ( self::should_skip_test( $test_context_element, $test_name, $test[3] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         continue;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,15 +133,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool True if the test case should be skipped. False otherwise.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        private static function should_skip_test( $test_name, $expected_tree ): bool {
-               if ( self::SKIP_HEAD_TESTS ) {
-                       $html_start = "<html>\n  <head>\n  <body>\n";
-                       if (
-                               strlen( $expected_tree ) < strlen( $html_start ) ||
-                               substr( $expected_tree, 0, strlen( $html_start ) ) !== $html_start
-                       ) {
-                               return true;
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static function should_skip_test( ?string $test_context_element, string $test_name, string $expected_tree ): bool {
+               if ( null !== $test_context_element && 'body' !== $test_context_element ) {
+                       return true;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( array_key_exists( $test_name, self::SKIP_TESTS ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -146,15 +155,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">        private static function build_tree_representation( ?string $fragment_context, string $html ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $processor = $fragment_context
</span><span class="cx" style="display: block; padding: 0 10px">                        ? WP_HTML_Processor::create_fragment( $html, "<{$fragment_context}>" )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        : WP_HTML_Processor::create_fragment( $html );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 : WP_HTML_Processor::create_full_parser( $html );
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( null === $processor ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $output = "<html>\n  <head>\n  <body>\n";
-
-               // Initially, assume we're 2 levels deep at: html > body > [position]
-               $indent_level = 2;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * The fragment parser will start in 2 levels deep at: html > body > [position]
+                * and requires adjustment to initial parameters.
+                * The full parser will not.
+                */
+               $output       = $fragment_context ? "<html>\n  <head>\n  <body>\n" : '';
+               $indent_level = $fragment_context ? 2 : 0;
</ins><span class="cx" style="display: block; padding: 0 10px">                 $indent       = '  ';
</span><span class="cx" style="display: block; padding: 0 10px">                $was_text     = null;
</span><span class="cx" style="display: block; padding: 0 10px">                $text_node    = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -238,6 +250,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        $text_node .= $processor->get_modifiable_text();
</span><span class="cx" style="display: block; padding: 0 10px">                                        break;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                case '#funky-comment':
+                                       // Comments must be "<" then "!-- " then the data then " -->".
+                                       $output .= str_repeat( $indent, $indent_level ) . "<!-- {$processor->get_modifiable_text()} -->\n";
+                                       break;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 case '#comment':
</span><span class="cx" style="display: block; padding: 0 10px">                                        switch ( $processor->get_comment_type() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                case WP_HTML_Processor::COMMENT_AS_ABRUPTLY_CLOSED_COMMENT:
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -250,6 +267,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $comment_text_content = "[CDATA[{$processor->get_modifiable_text()}]]";
</span><span class="cx" style="display: block; padding: 0 10px">                                                        break;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                case WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE:
+                                                       $comment_text_content = "?{$processor->get_tag()}{$processor->get_modifiable_text()}?";
+                                                       break;
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 default:
</span><span class="cx" style="display: block; padding: 0 10px">                                                        throw new Error( "Unhandled comment type for tree construction: {$processor->get_comment_type()}" );
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -301,6 +322,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $test_html            = '';
</span><span class="cx" style="display: block; padding: 0 10px">                $test_dom             = '';
</span><span class="cx" style="display: block; padding: 0 10px">                $test_context_element = null;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $test_script_flag     = false;
</ins><span class="cx" style="display: block; padding: 0 10px">                 $test_line_number     = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                while ( false !== ( $line = fgets( $handle ) ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -309,8 +331,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( '#' === $line[0] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // Finish section.
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( "#data\n" === $line ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // Yield when switching from a previous state.
-                                       if ( $state ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 /*
+                                        * Yield when switching from a previous state.
+                                        * Do not yield tests with the scripting flag enabled. The scripting flag
+                                        * is always disabled in the HTML API.
+                                        */
+                                       if ( $state && ! $test_script_flag ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 yield array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $test_line_number,
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $test_context_element,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -325,7 +351,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        $test_html            = '';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $test_dom             = '';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $test_context_element = null;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        $test_script_flag     = false;
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( "#script-on\n" === $line ) {
+                                       $test_script_flag = true;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                $state = trim( substr( $line, 1 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -376,7 +406,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 */
</span><span class="cx" style="display: block; padding: 0 10px">                                case 'document':
</span><span class="cx" style="display: block; padding: 0 10px">                                        if ( '|' === $line[0] ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                $test_dom .= substr( $line, 2 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         /*
+                                                * The next_token() method these tests rely on do not stop
+                                                * at doctype nodes. Strip doctypes from output.
+                                                * @todo Restore this line if and when the processor
+                                                * exposes doctypes.
+                                                */
+                                               if ( '| <!DOCTYPE ' !== substr( $line, 0, 12 ) ) {
+                                                       $test_dom .= substr( $line, 2 );
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                                         } else {
</span><span class="cx" style="display: block; padding: 0 10px">                                                // This is a text node that includes unescaped newlines.
</span><span class="cx" style="display: block; padding: 0 10px">                                                // Everything else should be singles lines starting with "| ".
</span></span></pre>
</div>
</div>

</body>
</html>