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

fix: doctype with entities handling #272

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 7 additions & 6 deletions lib/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,11 @@
continue;
}

if (parser.doctype && parser.doctype !== true) {
parser.sgmlDecl += c
continue;
}

if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
parser.state = S.DOCTYPE_DTD
parser.doctype += '<!' + parser.sgmlDecl + c
parser.sgmlDecl = ''
} else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
emitNode(parser, 'onopencdata')
parser.state = S.CDATA
parser.sgmlDecl = ''
Expand Down Expand Up @@ -1176,6 +1175,8 @@
parser.doctype += c
parser.state = S.DOCTYPE_DTD_QUOTED
parser.q = c
} else {
parser.doctype += c
}
continue

Expand Down
10 changes: 0 additions & 10 deletions test/doctype-with-comment.js

This file was deleted.

45 changes: 45 additions & 0 deletions test/doctypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// with entity
require(__dirname).test({
xml: '<!DOCTYPE svg [ <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> ]><svg></svg>',
expect: [
[ 'doctype', ' svg [ <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> ]' ],
[ 'opentagstart', { name: 'SVG', attributes: {} } ],
[ 'opentag', { name: 'SVG', attributes: {}, isSelfClosing: false } ],
[ 'closetag', 'SVG' ],
]
})

// with comment
require(__dirname).test({
xml: '<!DOCTYPE svg [<!--comment with \' and ] symbols-->]><svg></svg>',
expect: [
[ 'comment', 'comment with \' and ] symbols' ],
[ 'doctype', ' svg []' ],
[ 'opentagstart', { name: 'SVG', attributes: {} } ],
[ 'opentag', { name: 'SVG', attributes: {}, isSelfClosing: false } ],
[ 'closetag', 'SVG' ],
]
})

// with entity and comment
require(__dirname).test({
xml: '<!DOCTYPE svg [<!--comment with \' and ] symbols--> <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> ]><svg></svg>',
expect: [
[ 'comment', 'comment with \' and ] symbols' ],
[ 'doctype', ' svg [ <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/"> ]' ],
[ 'opentagstart', { name: 'SVG', attributes: {} } ],
[ 'opentag', { name: 'SVG', attributes: {}, isSelfClosing: false } ],
[ 'closetag', 'SVG' ],
]
})

// with empty doctype
require(__dirname).test({
xml: '<!DOCTYPE svg []><svg></svg>',
expect: [
[ 'doctype', ' svg []' ],
[ 'opentagstart', { name: 'SVG', attributes: {} } ],
[ 'opentag', { name: 'SVG', attributes: {}, isSelfClosing: false } ],
[ 'closetag', 'SVG' ],
]
})
Loading