Skip to content

Commit 2769d75

Browse files
committed
Safer create fragment at current node
1 parent 19d9599 commit 2769d75

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function get_supports(): array {
2323
* @return string|null The normalized HTML or null if not supported.
2424
*/
2525
function get_normalized_html( string $html, array $options ): ?string {
26+
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
27+
$cfacn->setAccessible( true );
28+
2629
if (
2730
method_exists( WP_HTML_Processor::class, 'create_fragment_at_current_node' ) &&
2831
$options['context_html']
@@ -40,7 +43,7 @@ function get_normalized_html( string $html, array $options ): ?string {
4043
* @var WP_HTML_Processor|null $processor
4144
* @disregard P1013
4245
*/
43-
$processor = $context_processor->create_fragment_at_current_node( $html );
46+
$processor = $cfacn->invoke( $context_processor, $html );
4447
}
4548
} else {
4649
$processor = WP_HTML_Processor::create_full_parser( $html );
@@ -73,6 +76,9 @@ function get_tree( string $html, array $options ): array {
7376
$processor_bookmarks = new ReflectionProperty( WP_HTML_Processor::class, 'bookmarks' );
7477
$processor_bookmarks->setAccessible( true );
7578

79+
$cfacn = new ReflectionMethod( WP_HTML_Processor::class, 'create_fragment_at_current_node' );
80+
$cfacn->setAccessible( true );
81+
7682
$is_fragment_processor = false;
7783

7884
$compat_mode = 'BackCompat';
@@ -121,7 +127,7 @@ function get_tree( string $html, array $options ): array {
121127
* @var WP_HTML_Processor|null $processor
122128
* @disregard P1013
123129
*/
124-
$processor = $context_processor->create_fragment_at_current_node( $html );
130+
$processor = $cfacn->invoke( $context_processor, $html );
125131
}
126132

127133
if ( ! isset( $processor ) ) {

0 commit comments

Comments
 (0)