Skip to content

Commit 8512f0f

Browse files
committed
HTML API: Apply HTML specification change to DOCTYPE parsing.
The HTML standard was updated to remove a distinction between empty and missing SYSTEM identifiers for the purposes of determining the mode of a document. See whatwg/html#12023. Developed in WordPress#12382 Props jonsurrell, dmsnell. Fixes #64504. git-svn-id: https://develop.svn.wordpress.org/trunk@62666 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d5914bd commit 8512f0f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/wp-includes/html-api/class-wp-html-doctype-info.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
* @see https://www.iso.org/standard/16387.html
5050
*
5151
* @since 6.7.0
52+
* @since 7.1.0 Spec update: missing and empty SYSTEM identifiers are handled
53+
* the same for determining the document mode.
5254
*
5355
* @access private
5456
*
@@ -229,13 +231,9 @@ private function __construct(
229231
* >
230232
* > The system identifier and public identifier strings must be compared...
231233
* > in an ASCII case-insensitive manner.
232-
* >
233-
* > A system identifier whose value is the empty string is not considered missing
234-
* > for the purposes of the conditions above.
235234
*/
236-
$system_identifier_is_missing = null === $system_identifier;
237-
$public_identifier = null === $public_identifier ? '' : strtolower( $public_identifier );
238-
$system_identifier = null === $system_identifier ? '' : strtolower( $system_identifier );
235+
$public_identifier = null === $public_identifier ? '' : strtolower( $public_identifier );
236+
$system_identifier = null === $system_identifier ? '' : strtolower( $system_identifier );
239237

240238
/*
241239
* > The public identifier is set to…
@@ -335,10 +333,11 @@ private function __construct(
335333
}
336334

337335
/*
338-
* > The system identifier is missing and the public identifier starts with…
336+
* > The system identifier is missing or the empty string, and the
337+
* > public identifier starts with…
339338
*/
340339
if (
341-
$system_identifier_is_missing && (
340+
'' === $system_identifier && (
342341
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 frameset//' ) ||
343342
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 transitional//' )
344343
)
@@ -364,10 +363,11 @@ private function __construct(
364363
}
365364

366365
/*
367-
* > The system identifier is not missing and the public identifier starts with…
366+
* > The system identifier is neither missing nor the empty string, and the
367+
* > public identifier starts with…
368368
*/
369369
if (
370-
! $system_identifier_is_missing && (
370+
'' !== $system_identifier && (
371371
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 frameset//' ) ||
372372
str_starts_with( $public_identifier, '-//w3c//dtd html 4.01 transitional//' )
373373
)

tests/phpunit/tests/html-api/wpHtmlDoctypeInfo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public static function data_parseable_raw_doctypes(): array {
8787
'Emoji' => array( '<!DOCTYPE 🏴󠁧󠁢󠁥󠁮󠁧󠁿 PUBLIC "🔥" "😈">', 'quirks', "\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}", '🔥', '😈' ),
8888
'Bogus characters instead of SYSTEM quote after public' => array( "<!DOCTYPE html PUBLIC ''x''>", 'quirks', 'html', '' ),
8989
'Special quirks mode if system unset' => array( '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//">', 'quirks', 'html', '-//W3C//DTD HTML 4.01 Frameset//' ),
90-
'Special limited-quirks mode if system set' => array( '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//" "">', 'limited-quirks', 'html', '-//W3C//DTD HTML 4.01 Frameset//', '' ),
90+
'Special quirks mode if system empty' => array( '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//" "">', 'quirks', 'html', '-//W3C//DTD HTML 4.01 Frameset//', '' ),
91+
'Special limited-quirks mode if system is non-empty' => array( '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//" "non-empty">', 'limited-quirks', 'html', '-//W3C//DTD HTML 4.01 Frameset//', 'non-empty' ),
9192
);
9293
}
9394

0 commit comments

Comments
 (0)