Skip to content

Commit

Permalink
HTML API: Backport updates from Core - stop processing after unsuppor…
Browse files Browse the repository at this point in the history
…ted markup

WordPress/wordpress-develop#5048 fixes a bug where the HTML Processor continues
to process input HTML once it encounters unsupported markup, which it shouldn't.
It should stop and abort all processing.
  • Loading branch information
dmsnell committed Sep 5, 2023
1 parent 10859af commit 9298814
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ public function next_tag( $query = null ) {
* @return bool Whether a tag was matched.
*/
public function step( $node_to_process = self::PROCESS_NEXT_NODE ) {
// Refuse to proceed if there was a previous error.
if ( null !== $this->last_error ) {
return false;
}

if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
$top_node = $this->state->stack_of_open_elements->current_node();
if ( $top_node && self::is_void( $top_node->node_name ) ) {
Expand Down Expand Up @@ -748,6 +753,10 @@ private function bookmark_tag() {
* @return string|null Name of currently matched tag in input HTML, or `null` if none found.
*/
public function get_tag() {
if ( null !== $this->last_error ) {
return null;
}

$tag_name = parent::get_tag();

switch ( $tag_name ) {
Expand Down

0 comments on commit 9298814

Please sign in to comment.