Skip to content

Commit

Permalink
new setting unparsedEntities
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen authored and isaacs committed Sep 26, 2023
1 parent a50af00 commit 56084e3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -1483,11 +1483,16 @@
}

if (c === ';') {
// parser[buffer] += parseEntity(parser)
var parsedEntity = parseEntity(parser)
parser.entity = ''
parser.state = returnState
parser.write(parsedEntity)
if (parser.opt.unparsedEntities) {
var parsedEntity = parseEntity(parser)
parser.entity = ''
parser.state = returnState
parser.write(parsedEntity)
} else {
parser[buffer] += parseEntity(parser)
parser.entity = ''
parser.state = returnState
}
} else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {
parser.entity += c
} else {
Expand Down
1 change: 1 addition & 0 deletions test/entity-elem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sax.ENTITIES.attr = "1";
sax.ENTITIES.text = "2.&attr;";
sax.ENTITIES.elem = '<B ATTR="&attr;.3"/>';
require(__dirname).test({
opt: {unparsedEntities: true},
xml: `<A ATTR="&attr;.2">&text;&elem;</A>`,
expect: [
["opentagstart", {name: "A", attributes: {}}],
Expand Down
1 change: 1 addition & 0 deletions test/entity-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var sax = require('../');
sax.ENTITIES.attr = "1";
sax.ENTITIES.text = "2.&attr;";
require(__dirname).test({
opt: {unparsedEntities: true},
xml: `<A>&text;</A>`,
expect: [
["opentagstart", {name: "A", attributes: {}}],
Expand Down

0 comments on commit 56084e3

Please sign in to comment.