From 8f5eb7a835291de74bba820d092500d23de537a2 Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Wed, 13 Nov 2024 12:20:15 +0000 Subject: [PATCH] HTML API: Include doctype in full parser serialize. Output DOCTYPE when calling `WP_HTML_Processor::serialize` on a full document that includes a DOCTYPE. The DOCTYPE should be included in the serialized/normalized HTML output as it has an impact in how the document is handled, in particular whether the document should be handled in quirks or no-quirks mode. This only affects the serialization of full parsers at this time because DOCTYPE tokens are currently ignored in all possible fragments. The omission of the DOCTYPE is subtle but can change the serialized document's quirks/no-quirks mode. Props jonsurrell. Fixes #62396. Built from https://develop.svn.wordpress.org/trunk@59399 git-svn-id: http://core.svn.wordpress.org/trunk@58785 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../html-api/class-wp-html-processor.php | 28 ++++++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php index 567b65062c..f6c561f010 100644 --- a/wp-includes/html-api/class-wp-html-processor.php +++ b/wp-includes/html-api/class-wp-html-processor.php @@ -1178,6 +1178,30 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { $token_type = $this->get_token_type(); switch ( $token_type ) { + case '#doctype': + $doctype = $this->get_doctype_info(); + if ( null === $doctype ) { + break; + } + + $html .= 'name ) { + $html .= " {$doctype->name}"; + } + + if ( null !== $doctype->public_identifier ) { + $html .= " PUBLIC \"{$doctype->public_identifier}\""; + } + if ( null !== $doctype->system_identifier ) { + if ( null === $doctype->public_identifier ) { + $html .= ' SYSTEM'; + } + $html .= " \"{$doctype->system_identifier}\""; + } + $html .= '>'; + break; + case '#text': $html .= htmlspecialchars( $this->get_modifiable_text(), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8' ); break; @@ -1194,10 +1218,6 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { case '#cdata-section': $html .= "get_modifiable_text()}]]>"; break; - - case 'html': - $html .= ''; - break; } if ( '#tag' !== $token_type ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 229f55972c..63ca53aa33 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59398'; +$wp_version = '6.8-alpha-59399'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.