Skip to content

Commit b271950

Browse files
committed
HTML API: Ensure non-string HTML input is safely handled.
Prevents an issue where passing `null` to HTML API constructors could result in runtime errors. Developed in WordPress/wordpress-develop#9545. Props kraftbj, jonsurrell, westonruter. Fixes #63854. Built from https://develop.svn.wordpress.org/trunk@60887 git-svn-id: http://core.svn.wordpress.org/trunk@60223 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 34ee9a6 commit b271950

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ public static function create_fragment( $html, $context = '<body>', $encoding =
297297
return null;
298298
}
299299

300+
if ( ! is_string( $html ) ) {
301+
_doing_it_wrong(
302+
__METHOD__,
303+
__( 'The HTML parameter must be a string.' ),
304+
'6.9.0'
305+
);
306+
return null;
307+
}
308+
300309
$context_processor = static::create_full_parser( "<!DOCTYPE html>{$context}", $encoding );
301310
if ( null === $context_processor ) {
302311
return null;
@@ -339,6 +348,14 @@ public static function create_full_parser( $html, $known_definite_encoding = 'UT
339348
if ( 'UTF-8' !== $known_definite_encoding ) {
340349
return null;
341350
}
351+
if ( ! is_string( $html ) ) {
352+
_doing_it_wrong(
353+
__METHOD__,
354+
__( 'The HTML parameter must be a string.' ),
355+
'6.9.0'
356+
);
357+
return null;
358+
}
342359

343360
$processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE );
344361
$processor->state->encoding = $known_definite_encoding;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,14 @@ class WP_HTML_Tag_Processor {
834834
* @param string $html HTML to process.
835835
*/
836836
public function __construct( $html ) {
837+
if ( ! is_string( $html ) ) {
838+
_doing_it_wrong(
839+
__METHOD__,
840+
__( 'The HTML parameter must be a string.' ),
841+
'6.9.0'
842+
);
843+
$html = '';
844+
}
837845
$this->html = $html;
838846
}
839847

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.9-alpha-60886';
19+
$wp_version = '6.9-alpha-60887';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)