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(sax): Restore ability to parse __prototype__ attributes #315

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
* @param {number} startIndex
*/
function addAttribute(qname, value, startIndex) {
if (qname in el.attributeNames) errorHandler.fatalError('Attribute ' + qname + ' redefined')
if (el.attributeNames.hasOwnProperty(qname)) {
errorHandler.fatalError('Attribute ' + qname + ' redefined')
}
el.addValue(qname, value, startIndex)
}
var attrName;
Expand Down
12 changes: 12 additions & 0 deletions test/parse/__snapshots__/parse-element.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ Object {
}
`;

exports[`XML Node Parse simple attributes should be able to have \`__prototype__\` attribute 1`] = `
Object {
"actual": "<xml __prototype__=\\"\\"/>",
}
`;

exports[`XML Node Parse simple attributes should be able to have \`constructor\` attribute 1`] = `
Object {
"actual": "<xml constructor=\\"\\"/>",
}
`;

exports[`XML Node Parse simple attributes unclosed root tag will be closed 1`] = `
Object {
"actual": "<xml a=\\"1\\" b=\\"2/\\"/>",
Expand Down
20 changes: 20 additions & 0 deletions test/parse/parse-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ describe('XML Node Parse', () => {

expect({ actual, ...errors }).toMatchSnapshot()
})

it('should be able to have `constructor` attribute', () => {
const { errors, parser } = getTestParser()

const actual = parser
.parseFromString('<xml constructor=""/>', 'text/xml')
.toString()

expect({ actual, ...errors }).toMatchSnapshot()
})

it('should be able to have `__prototype__` attribute', () => {
const { errors, parser } = getTestParser()

const actual = parser
.parseFromString('<xml __prototype__=""/>', 'text/xml')
.toString()

expect({ actual, ...errors }).toMatchSnapshot()
})
})

describe('namespaced attributes', () => {
Expand Down