From 9298814b072ca679b730d0fe93261479228765a5 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Tue, 22 Aug 2023 11:24:53 -0600 Subject: [PATCH] HTML API: Backport updates from Core - stop processing after unsupported 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. --- .../wordpress-6.4/html-api/class-wp-html-processor.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php b/lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php index b348a982a4686f..d7ec4017873139 100644 --- a/lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php +++ b/lib/compat/wordpress-6.4/html-api/class-wp-html-processor.php @@ -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 ) ) { @@ -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 ) {