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

Convert numeric character references representing < and & into &lt; and &amp; #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
17 changes: 15 additions & 2 deletions lib/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
}
}

function unescapePredefined (str) {
return str.replace(/&lt;/g, '<').replace(/&amp;/g, '&')
}

function checkBufferLength (parser) {
var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)
var maxActual = 0
Expand Down Expand Up @@ -644,10 +648,11 @@
parser.attribList.push([parser.attribName, parser.attribValue])
} else {
// in non-xmlns mode, we can emit the event right away
parser.tag.attributes[parser.attribName] = parser.attribValue
const unescapedAttribValue = unescapePredefined(parser.attribValue)
parser.tag.attributes[parser.attribName] = unescapedAttribValue
emitNode(parser, 'onattribute', {
name: parser.attribName,
value: parser.attribValue
value: unescapedAttribValue
})
}

Expand Down Expand Up @@ -827,6 +832,14 @@
num = parseInt(entity, 10)
numStr = num.toString(10)
}
switch (num) {
// Unescape these latter to avoid being treated now as starting
// new items
case 60: // '<'
return '&lt;'
case 38: // '&'
return '&amp;'
}
}
entity = entity.replace(/^0+/, '')
if (isNaN(num) || numStr.toLowerCase() !== entity) {
Expand Down
Loading