Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ const kElementsClosedByOpening = {
H5: { h5: true, H5: true },
h6: { h6: true, H6: true },
H6: { h6: true, H6: true },
dt: { dt: true, dd: true, DT: true, DD: true },
DT: { dt: true, dd: true, DT: true, DD: true },
dd: { dt: true, dd: true, DT: true, DD: true },
DD: { dt: true, dd: true, DT: true, DD: true },
} as Record<string, Record<string, boolean>>;
const kElementsClosedByClosing = {
li: { ul: true, ol: true, UL: true, OL: true },
Expand All @@ -1027,6 +1031,10 @@ const kElementsClosedByClosing = {
TD: { tr: true, table: true, TR: true, TABLE: true },
th: { tr: true, table: true, TR: true, TABLE: true },
TH: { tr: true, table: true, TR: true, TABLE: true },
dt: { dl: true, body: true, html: true, DL: true, BODY: true, HTML: true },
DT: { dl: true, body: true, html: true, DL: true, BODY: true, HTML: true },
dd: { dl: true, body: true, html: true, DL: true, BODY: true, HTML: true },
DD: { dl: true, body: true, html: true, DL: true, BODY: true, HTML: true },
} as Record<string, Record<string, boolean>>;
const kElementsClosedByClosingExcept = {
p: { a: true, audio: true, del: true, ins: true, map: true, noscript: true, video: true },
Expand Down
37 changes: 37 additions & 0 deletions test/tests/issues/315.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { parse } = require('@test/test-target');

describe('issue 315 unclosed dt/dd tags', function () {
it('keeps the document tree when dt and dd omit their end tags', function () {
const html = `<!DOCTYPE html>
<html>
<body>
<dl>
<dt>
<dd>
</dl>
</body>
</html>
`;
const root = parse(html);
root.querySelector('body').should.be.ok();
root.querySelector('dl').should.be.ok();
root.querySelectorAll('dt').length.should.eql(1);
root.querySelectorAll('dd').length.should.eql(1);
root.toString().should.containEql('<body>');
root.toString().should.containEql('<dl>');
});

it('does not drop body when a lone dt is unclosed', function () {
const root = parse('<!DOCTYPE html><html><body><dt></body></html>');
root.querySelector('body').should.be.ok();
root.querySelectorAll('dt').length.should.eql(1);
root.toString().should.containEql('<body>');
});

it('closes an open dt when a dd starts', function () {
const root = parse('<dl><dt>term<dd>def</dl>');
root.querySelector('dt').text.should.eql('term');
root.querySelector('dd').text.should.eql('def');
root.querySelector('dl').childNodes.filter((n) => n.tagName).map((n) => n.tagName).should.eql(['DT', 'DD']);
});
});