<!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>[57823] branches/6.5/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php: HTML API: Trigger active format reconstruction when reaching text nodes.</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/57823">57823</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/57823","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-03-13 09:28:48 +0000 (Wed, 13 Mar 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: Trigger active format reconstruction when reaching text nodes.

When encountering text nodes in an HTML document, the HTML parser needs
to run the active format reconstruction algorithm, even if it doesn't
stop to visit those text nodes. This is because the formats, which might
need reconstructing, will impact the breadcrumbs of all downstream nodes
from the text node.
In this patch, this process is triggered, which properly triggers the
active format reconstruction. It also enables the visiting of other token
types as is possible in the Tag Processor.

Developed in https://github.com/WordPress/wordpress-develop/pull/6054
Discussed in https://core.trac.wordpress.org/ticket/60170

Reviewed by swissspidy.
Merges <a href="https://core.trac.wordpress.org/changeset/57806">[57806]</a> to the to the 6.5 branch.

Props: dmsnell, jonsurrell, westonruter.
Fixes: <a href="https://core.trac.wordpress.org/ticket/60455">#60455</a>.
Follow-up to: <a href="https://core.trac.wordpress.org/changeset/57348">[57348]</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches65srcwpincludeshtmlapiclasswphtmlprocessorphp">branches/6.5/src/wp-includes/html-api/class-wp-html-processor.php</a></li>
<li><a href="#branches65testsphpunittestshtmlapiwpHtmlProcessorSemanticRulesphp">branches/6.5/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#branches65">branches/6.5/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/6.5
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/6.5 2024-03-12 18:52:20 UTC (rev 57822)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/6.5  2024-03-13 09:28:48 UTC (rev 57823)
</ins><a id="branches65"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/6.5</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43747,43751-43754,43758,43760-43765,43767-43770,43772,43774-43781,43783,43785,43790-43806,43808-43821,43825,43828,43830-43834,43836-43843,43846-43863,43867-43889,43891-43894,43897-43905,43908-43909,43911-43929,43931-43942,43946-43947,43949-43956,43959-43964,43967-43969,43988,43994,44014,44017,44047,44183,44185,44187-44206,44208-44213,44231-44232,44235,44248,44284,44287-44288
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.5:49373-49379,49381
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.8:51889
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:57791-57792,57804-57805,57809,57814,57817
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:57791-57792,57804-57806,57809,57814,57817
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches65srcwpincludeshtmlapiclasswphtmlprocessorphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.5/src/wp-includes/html-api/class-wp-html-processor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.5/src/wp-includes/html-api/class-wp-html-processor.php 2024-03-12 18:52:20 UTC (rev 57822)
+++ branches/6.5/src/wp-includes/html-api/class-wp-html-processor.php   2024-03-13 09:28:48 UTC (rev 57823)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -361,6 +361,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function next_tag( $query = null ) {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( null === $query ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        while ( $this->step() ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( '#tag' !== $this->get_token_type() ) {
+                                       continue;
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( ! $this->is_tag_closer() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        return true;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -384,6 +388,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! ( array_key_exists( 'breadcrumbs', $query ) && is_array( $query['breadcrumbs'] ) ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        while ( $this->step() ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                if ( '#tag' !== $this->get_token_type() ) {
+                                       continue;
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( ! $this->is_tag_closer() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        return true;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -405,6 +413,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $match_offset = isset( $query['match_offset'] ) ? (int) $query['match_offset'] : 1;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                while ( $match_offset > 0 && $this->step() ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        if ( '#tag' !== $this->get_token_type() ) {
+                               continue;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $this->matches_breadcrumbs( $breadcrumbs ) && 0 === --$match_offset ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                return true;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -428,13 +440,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function next_token() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $found_a_token = parent::next_token();
-
-               if ( '#tag' === $this->get_token_type() ) {
-                       $this->step( self::PROCESS_CURRENT_NODE );
-               }
-
-               return $found_a_token;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         return $this->step();
</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">@@ -463,10 +469,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool Whether the currently-matched tag is found at the given nested structure.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function matches_breadcrumbs( $breadcrumbs ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $this->get_tag() ) {
-                       return false;
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 // Everything matches when there are zero constraints.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 0 === count( $breadcrumbs ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -529,25 +531,35 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         *        is provided in the opening tag, otherwise it expects a tag closer.
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        $top_node = $this->state->stack_of_open_elements->current_node();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $top_node && self::is_void( $top_node->node_name ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if (
+                               $top_node && (
+                                       // Void elements.
+                                       self::is_void( $top_node->node_name ) ||
+                                       // Comments, text nodes, and other atomic tokens.
+                                       '#' === $top_node->node_name[0] ||
+                                       // Doctype declarations.
+                                       'html' === $top_node->node_name
+                               )
+                       ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $this->state->stack_of_open_elements->pop();
</span><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="cx" style="display: block; padding: 0 10px">                if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        while ( parent::next_token() && '#tag' !== $this->get_token_type() ) {
-                               continue;
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 parent::next_token();
</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">                // Finish stepping when there are no more tokens in the document.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( null === $this->get_tag() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if (
+                       WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT === $this->parser_state ||
+                       WP_HTML_Tag_Processor::STATE_COMPLETE === $this->parser_state
+               ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return false;
</span><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">                $this->state->current_token = new WP_HTML_Token(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->bookmark_tag(),
-                       $this->get_tag(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->bookmark_token(),
+                       $this->get_token_name(),
</ins><span class="cx" style="display: block; padding: 0 10px">                         $this->has_self_closing_flag(),
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->release_internal_bookmark_on_destruct
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -591,10 +603,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string[]|null Array of tag names representing path to matched node, if matched, otherwise NULL.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_breadcrumbs() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $this->get_tag() ) {
-                       return null;
-               }
-
</del><span class="cx" style="display: block; padding: 0 10px">                 $breadcrumbs = array();
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $this->state->stack_of_open_elements->walk_down() as $stack_item ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $breadcrumbs[] = $stack_item->node_name;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -619,11 +627,61 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return bool Whether an element was found.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function step_in_body() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $tag_name = $this->get_tag();
-               $op_sigil = $this->is_tag_closer() ? '-' : '+';
-               $op       = "{$op_sigil}{$tag_name}";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $token_name = $this->get_token_name();
+               $token_type = $this->get_token_type();
+               $op_sigil   = '#tag' === $token_type ? ( $this->is_tag_closer() ? '-' : '+' ) : '';
+               $op         = "{$op_sigil}{$token_name}";
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                switch ( $op ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        case '#comment':
+                       case '#funky-comment':
+                       case '#presumptuous-tag':
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       case '#text':
+                               $this->reconstruct_active_formatting_elements();
+
+                               $current_token = $this->bookmarks[ $this->state->current_token->bookmark_name ];
+
+                               /*
+                                * > A character token that is U+0000 NULL
+                                *
+                                * Any successive sequence of NULL bytes is ignored and won't
+                                * trigger active format reconstruction. Therefore, if the text
+                                * only comprises NULL bytes then the token should be ignored
+                                * here, but if there are any other characters in the stream
+                                * the active formats should be reconstructed.
+                                */
+                               if (
+                                       1 <= $current_token->length &&
+                                       "\x00" === $this->html[ $current_token->start ] &&
+                                       strspn( $this->html, "\x00", $current_token->start, $current_token->length ) === $current_token->length
+                               ) {
+                                       // Parse error: ignore the token.
+                                       return $this->step();
+                               }
+
+                               /*
+                                * Whitespace-only text does not affect the frameset-ok flag.
+                                * It is probably inter-element whitespace, but it may also
+                                * contain character references which decode only to whitespace.
+                                */
+                               $text = $this->get_modifiable_text();
+                               if ( strlen( $text ) !== strspn( $text, " \t\n\f\r" ) ) {
+                                       $this->state->frameset_ok = false;
+                               }
+
+                               $this->insert_html_element( $this->state->current_token );
+                               return true;
+
+                       case 'html':
+                               /*
+                                * > A DOCTYPE token
+                                * > Parse error. Ignore the token.
+                                */
+                               return $this->step();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         /*
</span><span class="cx" style="display: block; padding: 0 10px">                         * > A start tag whose tag name is "button"
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -711,7 +769,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        case '-SECTION':
</span><span class="cx" style="display: block; padding: 0 10px">                        case '-SUMMARY':
</span><span class="cx" style="display: block; padding: 0 10px">                        case '-UL':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $tag_name ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $token_name ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         // @todo Report parse error.
</span><span class="cx" style="display: block; padding: 0 10px">                                        // Ignore the token.
</span><span class="cx" style="display: block; padding: 0 10px">                                        return $this->step();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -718,10 +776,10 @@
</span><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">                                $this->generate_implied_end_tags();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( $this->state->stack_of_open_elements->current_node()->node_name !== $tag_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         // @todo Record parse error: this error doesn't impact parsing.
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $this->state->stack_of_open_elements->pop_until( $tag_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $this->state->stack_of_open_elements->pop_until( $token_name );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 return true;
</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">@@ -783,7 +841,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->generate_implied_end_tags();
</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 ( $this->state->stack_of_open_elements->current_node()->node_name !== $tag_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $this->state->stack_of_open_elements->current_node()->node_name !== $token_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         // @todo Record parse error: this error doesn't impact parsing.
</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">@@ -799,7 +857,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        case '+LI':
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->state->frameset_ok = false;
</span><span class="cx" style="display: block; padding: 0 10px">                                $node                     = $this->state->stack_of_open_elements->current_node();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $is_li                    = 'LI' === $tag_name;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $is_li                    = 'LI' === $token_name;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                in_body_list_loop:
</span><span class="cx" style="display: block; padding: 0 10px">                                /*
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -862,7 +920,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                         * then this is a parse error; ignore the token.
</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">-                                                'LI' === $tag_name &&
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'LI' === $token_name &&
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 ! $this->state->stack_of_open_elements->has_element_in_list_item_scope( 'LI' )
</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">@@ -872,8 +930,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                         * parse error; ignore the token.
</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">-                                                'LI' !== $tag_name &&
-                                               ! $this->state->stack_of_open_elements->has_element_in_scope( $tag_name )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         'LI' !== $token_name &&
+                                               ! $this->state->stack_of_open_elements->has_element_in_scope( $token_name )
</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">@@ -884,13 +942,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        return $this->step();
</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">-                                $this->generate_implied_end_tags( $tag_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $this->generate_implied_end_tags( $token_name );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( $tag_name !== $this->state->stack_of_open_elements->current_node()->node_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $token_name !== $this->state->stack_of_open_elements->current_node()->node_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         // @todo Indicate a parse error once it's possible. This error does not impact the logic here.
</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">-                                $this->state->stack_of_open_elements->pop_until( $tag_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $this->state->stack_of_open_elements->pop_until( $token_name );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 return true;
</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">@@ -1043,7 +1101,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 *
</span><span class="cx" style="display: block; padding: 0 10px">                 * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                switch ( $tag_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         switch ( $token_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         case 'APPLET':
</span><span class="cx" style="display: block; padding: 0 10px">                        case 'BASE':
</span><span class="cx" style="display: block; padding: 0 10px">                        case 'BASEFONT':
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1091,7 +1149,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        case 'TR':
</span><span class="cx" style="display: block; padding: 0 10px">                        case 'XMP':
</span><span class="cx" style="display: block; padding: 0 10px">                                $this->last_error = self::ERROR_UNSUPPORTED;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                throw new WP_HTML_Unsupported_Exception( "Cannot process {$tag_name} element." );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         throw new WP_HTML_Unsupported_Exception( "Cannot process {$token_name} element." );
</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 ( ! $this->is_tag_closer() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1113,7 +1171,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         * close anything beyond its containing `P` or `DIV` element.
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( $this->state->stack_of_open_elements->walk_up() as $node ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( $tag_name === $node->node_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $token_name === $node->node_name ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         break;
</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">@@ -1123,7 +1181,7 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->generate_implied_end_tags( $tag_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $this->generate_implied_end_tags( $token_name );
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $node !== $this->state->stack_of_open_elements->current_node() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                // @todo Record parse error: this error doesn't impact parsing.
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1142,19 +1200,16 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Creates a new bookmark for the currently-matched tag and returns the generated name.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Creates a new bookmark for the currently-matched token and returns the generated name.
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @since 6.4.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @since 6.5.0 Renamed from bookmark_tag() to bookmark_token().
</ins><span class="cx" style="display: block; padding: 0 10px">          *
</span><span class="cx" style="display: block; padding: 0 10px">         * @throws Exception When unable to allocate requested bookmark.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @return string|false Name of created bookmark, or false if unable to create.
</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 function bookmark_tag() {
-               if ( ! $this->get_tag() ) {
-                       return false;
-               }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function bookmark_token() {
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( ! parent::set_bookmark( ++$this->bookmark_counter ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->last_error = self::ERROR_EXCEEDED_MAX_BOOKMARKS;
</span><span class="cx" style="display: block; padding: 0 10px">                        throw new Exception( 'could not allocate bookmark' );
</span></span></pre></div>
<a id="branches65testsphpunittestshtmlapiwpHtmlProcessorSemanticRulesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.5/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.5/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php        2024-03-12 18:52:20 UTC (rev 57822)
+++ branches/6.5/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php  2024-03-13 09:28:48 UTC (rev 57823)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -128,6 +128,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 'DIV', $processor->get_tag(), 'Did not stop at initial DIV tag.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertFalse( $processor->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $processor->step();
+               $this->assertSame( '#text', $processor->get_token_type(), 'Should have found the text node.' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /*
</span><span class="cx" style="display: block; padding: 0 10px">                 * When encountering the BUTTON closing tag, there is no BUTTON in the stack of open elements.
</span><span class="cx" style="display: block; padding: 0 10px">                 * It should be ignored as there's no BUTTON to close.
</span></span></pre>
</div>
</div>

</body>
</html>