Skip to content

Commit

Permalink
HTML API: Fix unsupported insertion mode messages.
Browse files Browse the repository at this point in the history
Insertion modes in an HTML parser may include instructions like "process
the token in the IN HEAD insertion mode." The rules do not change the
insertion mode of the parser, but the errors are triggered outside of the
rules for the current insertion mode. These will be misleading when
bailing on these instructions, because it will point someone to the wrong
place in the code to find the source of the error.

In this patch all of the bail-points due to lacking insertion mode support
are hard-coded to better orient someone to the section of the code lacking
support for handling the input HTML.

Developed in WordPress/wordpress-develop#7043
Discussed in https://core.trac.wordpress.org/ticket/61576

Follow-up to [58679].

Props: dmsnell, jonsurrell.
See #61576.

Built from https://develop.svn.wordpress.org/trunk@58781


git-svn-id: https://core.svn.wordpress.org/trunk@58183 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
dmsnell committed Jul 22, 2024
1 parent d913f0f commit d8db9f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ public function get_current_depth(): int {
* @return bool Whether an element was found.
*/
private function step_initial(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_INITIAL . ' state.' );
}

/**
Expand All @@ -1007,7 +1007,7 @@ private function step_initial(): bool {
* @return bool Whether an element was found.
*/
private function step_before_html(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML . ' state.' );
}

/**
Expand All @@ -1026,7 +1026,7 @@ private function step_before_html(): bool {
* @return bool Whether an element was found.
*/
private function step_before_head(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HEAD . ' state.' );
}

/**
Expand All @@ -1045,7 +1045,7 @@ private function step_before_head(): bool {
* @return bool Whether an element was found.
*/
private function step_in_head(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD . ' state.' );
}

/**
Expand All @@ -1064,7 +1064,7 @@ private function step_in_head(): bool {
* @return bool Whether an element was found.
*/
private function step_in_head_noscript(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD_NOSCRIPT . ' state.' );
}

/**
Expand All @@ -1083,7 +1083,7 @@ private function step_in_head_noscript(): bool {
* @return bool Whether an element was found.
*/
private function step_after_head(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD . ' state.' );
}

/**
Expand Down Expand Up @@ -2127,7 +2127,7 @@ private function step_in_body(): bool {
* @return bool Whether an element was found.
*/
private function step_in_table(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE . ' state.' );
}

/**
Expand All @@ -2146,7 +2146,7 @@ private function step_in_table(): bool {
* @return bool Whether an element was found.
*/
private function step_in_table_text(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_TEXT . ' state.' );
}

/**
Expand All @@ -2165,7 +2165,7 @@ private function step_in_table_text(): bool {
* @return bool Whether an element was found.
*/
private function step_in_caption(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_CAPTION . ' state.' );
}

/**
Expand All @@ -2184,7 +2184,7 @@ private function step_in_caption(): bool {
* @return bool Whether an element was found.
*/
private function step_in_column_group(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP . ' state.' );
}

/**
Expand All @@ -2203,7 +2203,7 @@ private function step_in_column_group(): bool {
* @return bool Whether an element was found.
*/
private function step_in_table_body(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY . ' state.' );
}

/**
Expand All @@ -2222,7 +2222,7 @@ private function step_in_table_body(): bool {
* @return bool Whether an element was found.
*/
private function step_in_row(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_ROW . ' state.' );
}

/**
Expand All @@ -2241,7 +2241,7 @@ private function step_in_row(): bool {
* @return bool Whether an element was found.
*/
private function step_in_cell(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_CELL . ' state.' );
}

/**
Expand Down Expand Up @@ -2441,7 +2441,7 @@ private function step_in_select(): bool {
* @return bool Whether an element was found.
*/
private function step_in_select_in_table(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_SELECT_IN_TABLE . ' state.' );
}

/**
Expand All @@ -2460,7 +2460,7 @@ private function step_in_select_in_table(): bool {
* @return bool Whether an element was found.
*/
private function step_in_template(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE . ' state.' );
}

/**
Expand All @@ -2479,7 +2479,7 @@ private function step_in_template(): bool {
* @return bool Whether an element was found.
*/
private function step_after_body(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_BODY . ' state.' );
}

/**
Expand All @@ -2498,7 +2498,7 @@ private function step_after_body(): bool {
* @return bool Whether an element was found.
*/
private function step_in_frameset(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_FRAMESET . ' state.' );
}

/**
Expand All @@ -2517,7 +2517,7 @@ private function step_in_frameset(): bool {
* @return bool Whether an element was found.
*/
private function step_after_frameset(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_FRAMESET . ' state.' );
}

/**
Expand All @@ -2536,7 +2536,7 @@ private function step_after_frameset(): bool {
* @return bool Whether an element was found.
*/
private function step_after_after_body(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_AFTER_BODY . ' state.' );
}

/**
Expand All @@ -2555,7 +2555,7 @@ private function step_after_after_body(): bool {
* @return bool Whether an element was found.
*/
private function step_after_after_frameset(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_AFTER_FRAMESET . ' state.' );
}

/**
Expand All @@ -2574,7 +2574,7 @@ private function step_after_after_frameset(): bool {
* @return bool Whether an element was found.
*/
private function step_in_foreign_content(): bool {
$this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
$this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_FOREIGN_CONTENT . ' state.' );
}

/*
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-58780';
$wp_version = '6.7-alpha-58781';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit d8db9f2

Please sign in to comment.