Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Serialize normative html5 doctype or nothing #7793

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,22 +1184,9 @@ protected function serialize_token(): string {
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}\"";
if ( 'no-quirks' === $doctype->indicated_compatability_mode ) {
$html = '<!DOCTYPE html>';
}
$html .= '>';
break;

case '#text':
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ public function test_full_document_serialize_includes_doctype( string $doctype_i
public static function data_provider_serialize_doctype() {
return array(
'None' => array( '', '' ),
'Empty' => array( '<!DOCTYPE>', '<!DOCTYPE>' ),
'Empty' => array( '<!DOCTYPE>', '' ),
'HTML5' => array( '<!DOCTYPE html>', '<!DOCTYPE html>' ),
'Strange name' => array( '<!DOCTYPE WordPress>', '<!DOCTYPE wordpress>' ),
'With public' => array( '<!DOCTYPE html PUBLIC "x">', '<!DOCTYPE html PUBLIC "x">' ),
'With system' => array( '<!DOCTYPE html SYSTEM "y">', '<!DOCTYPE html SYSTEM "y">' ),
'With public and system' => array( '<!DOCTYPE html PUBLIC "x" "y">', '<!DOCTYPE html PUBLIC "x" "y">' ),
'Weird casing' => array( '<!docType HtmL pubLIc\'xxx\'"yyy" all this is ignored>', '<!DOCTYPE html PUBLIC "xxx" "yyy">' ),
'Strange name' => array( '<!DOCTYPE WordPress>', '' ),
'With public' => array( '<!DOCTYPE html PUBLIC "x">', '<!DOCTYPE html>' ),
'With system' => array( '<!DOCTYPE html SYSTEM "y">', '<!DOCTYPE html>' ),
'With public and system' => array( '<!DOCTYPE html PUBLIC "x" "y">', '<!DOCTYPE html>' ),
'Weird casing' => array( '<!docType HtmL pubLIc\'xxx\'"yyy" all this is ignored>', '<!DOCTYPE html>' ),
);
}
}
Loading