Make WordPress Core


Ignore:
Timestamp:
07/22/2024 11:19:20 PM (12 months ago)
Author:
dmsnell
Message:

HTML API: Fix unsupported insertion mode messages.

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

Follow-up to [58679].

Props: dmsnell, jonsurrell.
See #61576.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r58779 r58781  
    989989     */
    990990    private function step_initial(): bool {
    991         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     991        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_INITIAL . ' state.' );
    992992    }
    993993
     
    10081008     */
    10091009    private function step_before_html(): bool {
    1010         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1010        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HTML . ' state.' );
    10111011    }
    10121012
     
    10271027     */
    10281028    private function step_before_head(): bool {
    1029         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1029        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_BEFORE_HEAD . ' state.' );
    10301030    }
    10311031
     
    10461046     */
    10471047    private function step_in_head(): bool {
    1048         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1048        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD . ' state.' );
    10491049    }
    10501050
     
    10651065     */
    10661066    private function step_in_head_noscript(): bool {
    1067         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1067        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_HEAD_NOSCRIPT . ' state.' );
    10681068    }
    10691069
     
    10841084     */
    10851085    private function step_after_head(): bool {
    1086         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     1086        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_HEAD . ' state.' );
    10871087    }
    10881088
     
    21282128     */
    21292129    private function step_in_table(): bool {
    2130         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2130        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE . ' state.' );
    21312131    }
    21322132
     
    21472147     */
    21482148    private function step_in_table_text(): bool {
    2149         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2149        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_TEXT . ' state.' );
    21502150    }
    21512151
     
    21662166     */
    21672167    private function step_in_caption(): bool {
    2168         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2168        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_CAPTION . ' state.' );
    21692169    }
    21702170
     
    21852185     */
    21862186    private function step_in_column_group(): bool {
    2187         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2187        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_COLUMN_GROUP . ' state.' );
    21882188    }
    21892189
     
    22042204     */
    22052205    private function step_in_table_body(): bool {
    2206         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2206        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE_BODY . ' state.' );
    22072207    }
    22082208
     
    22232223     */
    22242224    private function step_in_row(): bool {
    2225         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2225        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_ROW . ' state.' );
    22262226    }
    22272227
     
    22422242     */
    22432243    private function step_in_cell(): bool {
    2244         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2244        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_CELL . ' state.' );
    22452245    }
    22462246
     
    24422442     */
    24432443    private function step_in_select_in_table(): bool {
    2444         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2444        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_SELECT_IN_TABLE . ' state.' );
    24452445    }
    24462446
     
    24612461     */
    24622462    private function step_in_template(): bool {
    2463         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2463        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_TEMPLATE . ' state.' );
    24642464    }
    24652465
     
    24802480     */
    24812481    private function step_after_body(): bool {
    2482         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2482        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_BODY . ' state.' );
    24832483    }
    24842484
     
    24992499     */
    25002500    private function step_in_frameset(): bool {
    2501         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2501        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_FRAMESET . ' state.' );
    25022502    }
    25032503
     
    25182518     */
    25192519    private function step_after_frameset(): bool {
    2520         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2520        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_FRAMESET . ' state.' );
    25212521    }
    25222522
     
    25372537     */
    25382538    private function step_after_after_body(): bool {
    2539         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2539        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_AFTER_BODY . ' state.' );
    25402540    }
    25412541
     
    25562556     */
    25572557    private function step_after_after_frameset(): bool {
    2558         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2558        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_AFTER_AFTER_FRAMESET . ' state.' );
    25592559    }
    25602560
     
    25752575     */
    25762576    private function step_in_foreign_content(): bool {
    2577         $this->bail( "No support for parsing in the '{$this->state->insertion_mode}' state." );
     2577        $this->bail( 'No support for parsing in the ' . WP_HTML_Processor_State::INSERTION_MODE_IN_FOREIGN_CONTENT . ' state.' );
    25782578    }
    25792579
Note: See TracChangeset for help on using the changeset viewer.