diff --git a/lib/sax.js b/lib/sax.js index a7fa74ba6..6795df61c 100644 --- a/lib/sax.js +++ b/lib/sax.js @@ -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; diff --git a/test/parse/__snapshots__/parse-element.test.js.snap b/test/parse/__snapshots__/parse-element.test.js.snap index b4f7dcba1..50e2ddfd4 100644 --- a/test/parse/__snapshots__/parse-element.test.js.snap +++ b/test/parse/__snapshots__/parse-element.test.js.snap @@ -10,6 +10,18 @@ Object { } `; +exports[`XML Node Parse simple attributes should be able to have \`__prototype__\` attribute 1`] = ` +Object { + "actual": "", +} +`; + +exports[`XML Node Parse simple attributes should be able to have \`constructor\` attribute 1`] = ` +Object { + "actual": "", +} +`; + exports[`XML Node Parse simple attributes unclosed root tag will be closed 1`] = ` Object { "actual": "", diff --git a/test/parse/parse-element.test.js b/test/parse/parse-element.test.js index 404b9cb7e..3f550b996 100644 --- a/test/parse/parse-element.test.js +++ b/test/parse/parse-element.test.js @@ -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('', 'text/xml') + .toString() + + expect({ actual, ...errors }).toMatchSnapshot() + }) + + it('should be able to have `__prototype__` attribute', () => { + const { errors, parser } = getTestParser() + + const actual = parser + .parseFromString('', 'text/xml') + .toString() + + expect({ actual, ...errors }).toMatchSnapshot() + }) }) describe('namespaced attributes', () => {