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. Reviewed by cbravobernal. Merges [59399] to the 6.7 branch. Props jonsurrell. Fixes #62396. Built from https://develop.svn.wordpress.org/branches/6.7@59401 git-svn-id: http://core.svn.wordpress.org/branches/6.7@58787 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2cd5737c13
commit
7d29e45bbe
|
@ -1157,6 +1157,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 .= '<!DOCTYPE';
|
||||
|
||||
if ( $doctype->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;
|
||||
|
@ -1173,10 +1197,6 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
|
|||
case '#cdata-section':
|
||||
$html .= "<![CDATA[{$this->get_modifiable_text()}]]>";
|
||||
break;
|
||||
|
||||
case 'html':
|
||||
$html .= '<!DOCTYPE html>';
|
||||
break;
|
||||
}
|
||||
|
||||
if ( '#tag' !== $token_type ) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.7.1-alpha-59396';
|
||||
$wp_version = '6.7.1-alpha-59401';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue