Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/wp-includes/html-api/class-wp-html-processor-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,9 @@ class WP_HTML_Processor_State {
* Context node initializing fragment parser, if created as a fragment parser.
*
* @since 6.4.0
* @deprecated 6.8.0 WP_HTML_Processor tracks the context_node internally.
*
* @see https://html.spec.whatwg.org/#concept-frag-parse-context
*
* @var [string, array]|null
* @var null
*/
public $context_node = null;

Expand Down
12 changes: 1 addition & 11 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ public static function create_fragment( $html, $context = '<body>', $encoding =
}

$processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE );
$processor->state->context_node = array( 'BODY', array() );
$processor->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY;
$processor->state->encoding = $encoding;
$processor->state->encoding_confidence = 'certain';
Expand All @@ -317,7 +316,7 @@ public static function create_fragment( $html, $context = '<body>', $encoding =

$context_node = new WP_HTML_Token(
'context-node',
$processor->state->context_node[0],
'BODY',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something seems off here: why are we hard-coding BODY as the context node? it seems like we missed this in line 301 when we added support for other contexts, whereas that line should have been updated to something like $...->context_node[0] but now we’re moving in the opposite direction…?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This landed before the additional context support and I believe all these lines are now stale.

In this change, the <body> context was still hard-coded above. It moved out of the ->state->context_node and into this location, while remaining hard-coded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant lines are now around here:

$tag_name = $this->current_element->token->node_name;

$fragment_processor->context_node = clone $this->current_element->token;
$fragment_processor->context_node->bookmark_name = 'context-node';
$fragment_processor->context_node->on_destroy = null;

false
);

Expand Down Expand Up @@ -492,15 +491,6 @@ public function create_fragment_at_current_node( string $html ) {
$fragment_processor->context_node->bookmark_name = 'context-node';
$fragment_processor->context_node->on_destroy = null;

$fragment_processor->state->context_node = array( $fragment_processor->context_node->node_name, array() );

$attribute_names = $this->get_attribute_names_with_prefix( '' );
if ( null !== $attribute_names ) {
foreach ( $attribute_names as $name ) {
$fragment_processor->state->context_node[1][ $name ] = $this->get_attribute( $name );
}
}

$fragment_processor->breadcrumbs = array( 'HTML', $fragment_processor->context_node->node_name );

if ( 'TEMPLATE' === $fragment_processor->context_node->node_name ) {
Expand Down
Loading