Skip to content

Commit 5908f03

Browse files
committed
HTML API: Move "any other end tag" handling to a separate method.
Extract the _in body_ insertion mode's "any other end tag" steps into their own method so they can be invoked directly, such as from the adoption agency algorithm. Developed in WordPress#12267. Props jonsurrell, dmsnell. See #65383. git-svn-id: https://develop.svn.wordpress.org/trunk@62563 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 25850a6 commit 5908f03

1 file changed

Lines changed: 45 additions & 23 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,38 +3257,60 @@ private function step_in_body(): bool {
32573257
/*
32583258
* > Any other end tag
32593259
*/
3260+
return $this->in_body_any_other_end_tag();
3261+
}
32603262

3261-
/*
3262-
* Find the corresponding tag opener in the stack of open elements, if
3263-
* it exists before reaching a special element, which provides a kind
3264-
* of boundary in the stack. For example, a `</custom-tag>` should not
3265-
* close anything beyond its containing `P` or `DIV` element.
3266-
*/
3267-
foreach ( $this->state->stack_of_open_elements->walk_up() as $node ) {
3268-
if ( 'html' === $node->namespace && $token_name === $node->node_name ) {
3269-
break;
3270-
}
3263+
$this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
3264+
// This unnecessary return prevents tools from inaccurately reporting type errors.
3265+
return false;
3266+
}
32713267

3272-
if ( self::is_special( $node ) ) {
3273-
// This is a parse error, ignore the token.
3274-
return $this->step();
3275-
}
3268+
/**
3269+
* Applies the "any other end tag" parsing instructions for the IN BODY insertion mode.
3270+
*
3271+
* @since 7.1.0
3272+
* @ignore
3273+
*
3274+
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
3275+
*
3276+
* @see https://html.spec.whatwg.org/#parsing-main-inbody
3277+
* @see WP_HTML_Processor::step_in_body
3278+
*
3279+
* @return bool Whether an element was found.
3280+
*/
3281+
private function in_body_any_other_end_tag(): bool {
3282+
$token_name = $this->get_token_name();
3283+
3284+
/*
3285+
* Find the corresponding tag opener in the stack of open elements, if
3286+
* it exists before reaching a special element, which provides a kind
3287+
* of boundary in the stack. For example, a `</custom-tag>` should not
3288+
* close anything beyond its containing `P` or `DIV` element.
3289+
*/
3290+
foreach ( $this->state->stack_of_open_elements->walk_up() as $node ) {
3291+
if ( 'html' === $node->namespace && $token_name === $node->node_name ) {
3292+
break;
32763293
}
32773294

3278-
$this->generate_implied_end_tags( $token_name );
3279-
if ( $node !== $this->state->stack_of_open_elements->current_node() ) {
3280-
// @todo Record parse error: this error doesn't impact parsing.
3295+
if ( self::is_special( $node ) ) {
3296+
// This is a parse error, ignore the token.
3297+
return $this->step();
32813298
}
3299+
}
32823300

3283-
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
3284-
$this->state->stack_of_open_elements->pop();
3285-
if ( $node === $item ) {
3286-
return true;
3287-
}
3301+
$this->generate_implied_end_tags( $token_name );
3302+
if ( $node !== $this->state->stack_of_open_elements->current_node() ) {
3303+
// @todo Record parse error: this error doesn't impact parsing.
3304+
}
3305+
3306+
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
3307+
$this->state->stack_of_open_elements->pop();
3308+
if ( $node === $item ) {
3309+
return true;
32883310
}
32893311
}
32903312

3291-
$this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
3313+
$this->bail( 'Should not have been able to reach end of "any other end tag" IN BODY processing. Check HTML API code.' );
32923314
// This unnecessary return prevents tools from inaccurately reporting type errors.
32933315
return false;
32943316
}

0 commit comments

Comments
 (0)