Skip to content

Commit 8b722d4

Browse files
committed
Revert changes to WP_HTML_Tag_Processor and add errors to non-baseline ignore list
1 parent 962a7e8 commit 8b722d4

3 files changed

Lines changed: 81 additions & 67 deletions

File tree

‎phpstan.neon.dist‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,16 @@ parameters:
150150
message: '#^Parameter \#4 \$length of function substr_compare expects int, null given\.$#'
151151
path: src/wp-includes/html-api/class-wp-html-tag-processor.php
152152
reportUnmatched: false
153+
154+
# HTML API:
155+
# These errors are ignored for the sake of making it easier to keep the HTML Processor in sync with the HTML spec.
156+
-
157+
message: '#^Comparison operation "\>" between 999\|1000 and 0 is always true\.$#'
158+
identifier: greater.alwaysTrue
159+
count: 1
160+
path: src/wp-includes/html-api/class-wp-html-processor.php
161+
-
162+
message: '#^Comparison operation "\>\=" between 0 and 8 is always false\.$#'
163+
identifier: greaterOrEqual.alwaysFalse
164+
count: 1
165+
path: src/wp-includes/html-api/class-wp-html-processor.php

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

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6096,6 +6096,7 @@ private function reset_insertion_mode_appropriately(): void {
60966096
* @see https://html.spec.whatwg.org/#adoption-agency-algorithm
60976097
*/
60986098
private function run_adoption_agency_algorithm(): void {
6099+
$budget = 1000;
60996100
$subject = $this->get_tag();
61006101
$current_node = $this->state->stack_of_open_elements->current_node();
61016102

@@ -6109,88 +6110,88 @@ private function run_adoption_agency_algorithm(): void {
61096110
return;
61106111
}
61116112

6112-
/*
6113-
* > Let outer loop counter be 0.
6114-
* > Outer loop: If outer loop counter is greater than or equal to 8, then return.
6115-
*
6116-
* Only the first pass through the outer loop is supported. Every path through it
6117-
* either returns or bails before reaching the steps that would start another pass,
6118-
* so the loop and its counter are left out until those steps are implemented.
6119-
*/
6120-
6121-
/*
6122-
* > Let formatting element be the last element in the list of active formatting elements that:
6123-
* > - is between the end of the list and the last marker in the list,
6124-
* > if any, or the start of the list otherwise,
6125-
* > - and has the tag name subject.
6126-
*/
6127-
$formatting_element = null;
6128-
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
6129-
if ( 'marker' === $item->node_name ) {
6130-
break;
6113+
$outer_loop_counter = 0;
6114+
while ( $budget-- > 0 ) {
6115+
if ( $outer_loop_counter++ >= 8 ) {
6116+
return;
61316117
}
61326118

6133-
if ( $subject === $item->node_name ) {
6134-
$formatting_element = $item;
6135-
break;
6136-
}
6137-
}
6138-
6139-
// > If there is no such element, then return and instead act as described in the "any other end tag" entry above.
6140-
if ( null === $formatting_element ) {
6141-
$this->bail( 'Cannot run adoption agency when "any other end tag" is required.' );
6142-
}
6119+
/*
6120+
* > Let formatting element be the last element in the list of active formatting elements that:
6121+
* > - is between the end of the list and the last marker in the list,
6122+
* > if any, or the start of the list otherwise,
6123+
* > - and has the tag name subject.
6124+
*/
6125+
$formatting_element = null;
6126+
foreach ( $this->state->active_formatting_elements->walk_up() as $item ) {
6127+
if ( 'marker' === $item->node_name ) {
6128+
break;
6129+
}
61436130

6144-
// > If formatting element is not in the stack of open elements, then this is a parse error; remove the element from the list, and return.
6145-
if ( ! $this->state->stack_of_open_elements->contains_node( $formatting_element ) ) {
6146-
$this->state->active_formatting_elements->remove_node( $formatting_element );
6147-
return;
6148-
}
6131+
if ( $subject === $item->node_name ) {
6132+
$formatting_element = $item;
6133+
break;
6134+
}
6135+
}
61496136

6150-
// > If formatting element is in the stack of open elements, but the element is not in scope, then this is a parse error; return.
6151-
if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $formatting_element->node_name ) ) {
6152-
return;
6153-
}
6137+
// > If there is no such element, then return and instead act as described in the "any other end tag" entry above.
6138+
if ( null === $formatting_element ) {
6139+
$this->bail( 'Cannot run adoption agency when "any other end tag" is required.' );
6140+
}
61546141

6155-
/*
6156-
* > Let furthest block be the topmost node in the stack of open elements that is lower in the stack
6157-
* > than formatting element, and is an element in the special category. There might not be one.
6158-
*/
6159-
$is_above_formatting_element = true;
6160-
$furthest_block = null;
6161-
foreach ( $this->state->stack_of_open_elements->walk_down() as $item ) {
6162-
if ( $is_above_formatting_element && $formatting_element->bookmark_name !== $item->bookmark_name ) {
6163-
continue;
6142+
// > If formatting element is not in the stack of open elements, then this is a parse error; remove the element from the list, and return.
6143+
if ( ! $this->state->stack_of_open_elements->contains_node( $formatting_element ) ) {
6144+
$this->state->active_formatting_elements->remove_node( $formatting_element );
6145+
return;
61646146
}
61656147

6166-
if ( $is_above_formatting_element ) {
6167-
$is_above_formatting_element = false;
6168-
continue;
6148+
// > If formatting element is in the stack of open elements, but the element is not in scope, then this is a parse error; return.
6149+
if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $formatting_element->node_name ) ) {
6150+
return;
61696151
}
61706152

6171-
if ( self::is_special( $item ) ) {
6172-
$furthest_block = $item;
6173-
break;
6153+
/*
6154+
* > Let furthest block be the topmost node in the stack of open elements that is lower in the stack
6155+
* > than formatting element, and is an element in the special category. There might not be one.
6156+
*/
6157+
$is_above_formatting_element = true;
6158+
$furthest_block = null;
6159+
foreach ( $this->state->stack_of_open_elements->walk_down() as $item ) {
6160+
if ( $is_above_formatting_element && $formatting_element->bookmark_name !== $item->bookmark_name ) {
6161+
continue;
6162+
}
6163+
6164+
if ( $is_above_formatting_element ) {
6165+
$is_above_formatting_element = false;
6166+
continue;
6167+
}
6168+
6169+
if ( self::is_special( $item ) ) {
6170+
$furthest_block = $item;
6171+
break;
6172+
}
61746173
}
6175-
}
61766174

6177-
/*
6178-
* > If there is no furthest block, then the UA must first pop all the nodes from the bottom of the
6179-
* > stack of open elements, from the current node up to and including formatting element, then
6180-
* > remove formatting element from the list of active formatting elements, and finally return.
6181-
*/
6182-
if ( null === $furthest_block ) {
6183-
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
6184-
$this->state->stack_of_open_elements->pop();
6175+
/*
6176+
* > If there is no furthest block, then the UA must first pop all the nodes from the bottom of the
6177+
* > stack of open elements, from the current node up to and including formatting element, then
6178+
* > remove formatting element from the list of active formatting elements, and finally return.
6179+
*/
6180+
if ( null === $furthest_block ) {
6181+
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
6182+
$this->state->stack_of_open_elements->pop();
61856183

6186-
if ( $formatting_element->bookmark_name === $item->bookmark_name ) {
6187-
$this->state->active_formatting_elements->remove_node( $formatting_element );
6188-
return;
6184+
if ( $formatting_element->bookmark_name === $item->bookmark_name ) {
6185+
$this->state->active_formatting_elements->remove_node( $formatting_element );
6186+
return;
6187+
}
61896188
}
61906189
}
6190+
6191+
$this->bail( 'Cannot extract common ancestor in adoption agency algorithm.' );
61916192
}
61926193

6193-
$this->bail( 'Cannot extract common ancestor in adoption agency algorithm.' );
6194+
$this->bail( 'Cannot run adoption agency when looping required.' );
61946195
}
61956196

61966197
/**

‎tests/phpstan/baselines/deadCode.unreachable.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ parameters:
5656
-
5757
message: '#^Unreachable statement \- code above always terminates\.$#'
5858
identifier: deadCode.unreachable
59-
count: 30
59+
count: 31
6060
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
6161
-
6262
message: '#^Unreachable statement \- code above always terminates\.$#'

0 commit comments

Comments
 (0)