HTML API: Stop processing HTML when encountering unsupported markup.

It was a design goal of the HTML Processor to abort processing its input document when encountering unsupported markup. Unfortunately there was no test for this and so-far, the HTML Processor has paused, but continued processing in these situations.

In this patch a new test ensures that the HTML Processor stops and refuses to move forward after encountering any unsupported markup. It also ensures that it doesn't report any current tag names since unsupported markup could imply that the read tag name is different than the parsed tag name.

Props dmsnell.
Fixes #59167.
Built from https://develop.svn.wordpress.org/trunk@56493


git-svn-id: http://core.svn.wordpress.org/trunk@56005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Bernhard Reiter 2023-08-30 15:39:16 +00:00
parent 8429956b09
commit c67fe4b6e5
2 changed files with 10 additions and 1 deletions

View File

@ -432,6 +432,11 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
* @return bool Whether a tag was matched. * @return bool Whether a tag was matched.
*/ */
public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { 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 ) { if ( self::PROCESS_NEXT_NODE === $node_to_process ) {
$top_node = $this->state->stack_of_open_elements->current_node(); $top_node = $this->state->stack_of_open_elements->current_node();
if ( $top_node && self::is_void( $top_node->node_name ) ) { if ( $top_node && self::is_void( $top_node->node_name ) ) {
@ -744,6 +749,10 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
* @return string|null Name of currently matched tag in input HTML, or `null` if none found. * @return string|null Name of currently matched tag in input HTML, or `null` if none found.
*/ */
public function get_tag() { public function get_tag() {
if ( null !== $this->last_error ) {
return null;
}
$tag_name = parent::get_tag(); $tag_name = parent::get_tag();
switch ( $tag_name ) { switch ( $tag_name ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56492'; $wp_version = '6.4-alpha-56493';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.