Skip to content

Commit 4698fe5

Browse files
committed
Fix self-closing foreign content tag tree depth
1 parent 2db9383 commit 4698fe5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

html-api-debugger/html-api-integration.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ function get_tree( string $html, array $options ): array {
216216
}
217217
}
218218

219+
$namespace = method_exists( WP_HTML_Processor::class, 'get_namespace' ) ? $processor->get_namespace() : 'html';
219220
$self = array(
220221
'nodeType' => NODE_TYPE_ELEMENT,
221222
'nodeName' => $tag_name,
@@ -227,7 +228,7 @@ function get_tree( string $html, array $options ): array {
227228
'_bc' => $processor->get_breadcrumbs(),
228229
'_virtual' => $is_virtual(),
229230
'_depth' => $get_current_depth(),
230-
'_namespace' => method_exists( WP_HTML_Processor::class, 'get_namespace' ) ? $processor->get_namespace() : 'html',
231+
'_namespace' => $namespace,
231232
);
232233

233234
// Self-contained tags contain their inner contents as modifiable text.
@@ -247,7 +248,10 @@ function get_tree( string $html, array $options ): array {
247248

248249
$current['childNodes'][] = $self;
249250

250-
if ( $processor->is_tag_closer() ) {
251+
if (
252+
$processor->is_tag_closer() ||
253+
( $namespace !== 'html' && $processor->has_self_closing_flag() )
254+
) {
251255
break;
252256
}
253257

html-api-debugger/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ Add a page to wp-admin for debugging the HTML API.
8888

8989
= 1.8 =
9090
* Highlight spans in HTML input on hover.
91+
* Fix a bug in tree construction with self-closing tags in foreign content.

0 commit comments

Comments
 (0)