Skip to content

Commit

Permalink
Remove null values from document types
Browse files Browse the repository at this point in the history
BREAKING: The serialization of document types stored in the htmlparser2 adapter now no longer has an empty trailing string. Ie. `<!DOCTYPE html "">` is now `<!DOCTYPE html>`.
  • Loading branch information
fb55 committed Mar 7, 2022
1 parent 55d414b commit 38639f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions packages/parse5-htmlparser2-tree-adapter/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ export function getTemplateContent(templateElement: Element): Document {
return templateElement.children[0] as Document;
}

export function setDocumentType(
document: Document,
name: string | null,
publicId: string | null,
systemId: string | null
): void {
export function setDocumentType(document: Document, name: string, publicId: string, systemId: string): void {
const data = doctype.serializeContent(name, publicId, systemId);
let doctypeNode = document.children.find(
(node): node is ProcessingInstruction => isDirective(node) && node.name === '!doctype'
Expand Down
4 changes: 2 additions & 2 deletions packages/parse5/lib/common/doctype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function getDocumentMode(token: DoctypeToken): DOCUMENT_MODE {
return DOCUMENT_MODE.NO_QUIRKS;
}

export function serializeContent(name: string | null, publicId: string | null, systemId: string | null): string {
export function serializeContent(name: string, publicId: string, systemId: string): string {
let str = '!DOCTYPE ';

if (name) {
Expand All @@ -153,7 +153,7 @@ export function serializeContent(name: string | null, publicId: string | null, s
str += ' SYSTEM';
}

if (systemId !== null) {
if (systemId) {
str += ` ${enquoteDoctypeId(systemId)}`;
}

Expand Down

0 comments on commit 38639f3

Please sign in to comment.