Skip to content

Commit

Permalink
Support after body elements but not comments
Browse files Browse the repository at this point in the history
Ideally, we could support all of this and only bail if the processor
prints a comment and then re-enters.
  • Loading branch information
sirreal committed Aug 9, 2024
1 parent 6d5fbf2 commit a1304b5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4023,13 +4023,14 @@ private function step_after_body(): bool {

/*
* > A comment token
*
* Presumptuous tags "</>" are ignored here because they will not appear in HTML and it's undesirable to bail on them here.
*/
case '#cdata-section':
case '#comment':
case '#funky-comment':
case '#presumptuous-tag':
$this->insert_html_element( $this->state->current_token );
return true;
$this->bail( 'Cannot process comments after BODY which may appear out-of-order.' );
break;

/*
* > A DOCTYPE token
Expand Down Expand Up @@ -4065,7 +4066,8 @@ private function step_after_body(): bool {
* > Parse error. Switch the insertion mode to "in body" and reprocess the token.
*/
after_body_anything_else:
$this->bail( 'Cannot process any tokens after closing the BODY which would require re-opening it.' );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
return $this->step( self::REPROCESS_CURRENT_NODE );
}

/**
Expand Down Expand Up @@ -4289,13 +4291,14 @@ private function step_after_after_body(): bool {
switch ( $op ) {
/*
* > A comment token
*
* Presumptuous tags "</>" are ignored here because they will not appear in HTML and it's undesirable to bail on them here.
*/
case '#cdata-section':
case '#comment':
case '#funky-comment':
case '#presumptuous-tag':
$this->insert_html_element( $this->state->current_token );
return true;
$this->bail( 'Cannot process comments after BODY which may appear out-of-order.' );
break;

/*
* > A DOCTYPE token
Expand Down Expand Up @@ -4326,7 +4329,8 @@ private function step_after_after_body(): bool {
* > Parse error. Switch the insertion mode to "in body" and reprocess the token.
*/
after_after_body_anything_else:
$this->bail( 'Cannot process any tokens after closing the BODY which would require re-opening it.' );
$this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
return $this->step( self::REPROCESS_CURRENT_NODE );
}

/**
Expand Down

0 comments on commit a1304b5

Please sign in to comment.