Skip to content
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
2 changes: 1 addition & 1 deletion lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class exports.Parser extends events
@emit err

assignOrPush: (obj, key, newValue) =>
if key not of obj
if not Object::hasOwnProperty.call obj, key
if not @options.explicitArray
defineProperty obj, key, newValue
else
Expand Down
20 changes: 20 additions & 0 deletions test/parser.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,23 @@ module.exports =
.catch (err) ->
assert.notEqual err, null
test.finish()

# Regression test for issue #719: prototype chain property confusion
# Tags named after Object.prototype methods should parse correctly
'test prototype property names do not cause errors': skeleton({__xmlString: '<root><toString>value1</toString><valueOf>value2</valueOf><constructor>value3</constructor><hasOwnProperty>value4</hasOwnProperty></root>'}, (r) ->
console.log 'Result object: ' + util.inspect r, false, 10
# Verify all prototype-named tags parsed as strings, not functions
equ r.root.toString[0], 'value1'
equ r.root.valueOf[0], 'value2'
equ r.root.constructor[0], 'value3'
equ r.root.hasOwnProperty[0], 'value4'
# Verify no inherited functions leaked into the result
equ typeof r.root.toString[0], 'string'
equ typeof r.root.valueOf[0], 'string')

'test multiple prototype property tags parse correctly': skeleton({__xmlString: '<root><toString>a</toString><toString>b</toString></root>'}, (r) ->
console.log 'Result object: ' + util.inspect r, false, 10
# Multiple tags with prototype names should be collected into arrays
equ r.root.toString.length, 2
equ r.root.toString[0], 'a'
equ r.root.toString[1], 'b')