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#7043
Discussed in https://core.trac.wordpress.org/ticket/61576

Follow-up to [58679].

Props: dmsnell, jonsurrell.
See #61576.


git-svn-id: https://develop.svn.wordpress.org/trunk@58781 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
dmsnell authored and aslamdoctor committed Dec 28, 2024
1 parent 80190d4 commit e3dfec1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/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

0 comments on commit e3dfec1

Please sign in to comment.