-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Object.create(null) to create all parsed objects (prevent prototy…
…pe replacement)
- Loading branch information
1 parent
1832e0b
commit 581b19a
Showing
3 changed files
with
20 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,12 +102,12 @@ class exports.Parser extends events | |
charkey = @options.charkey | ||
|
||
@saxParser.onopentag = (node) => | ||
obj = {} | ||
obj = Object.create(null) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Leonidas-from-XIV
Owner
|
||
obj[charkey] = "" | ||
unless @options.ignoreAttrs | ||
for own key of node.attributes | ||
if attrkey not of obj and not @options.mergeAttrs | ||
obj[attrkey] = {} | ||
obj[attrkey] = Object.create(null) | ||
This comment has been minimized.
Sorry, something went wrong.
guimard
|
||
newValue = if @options.attrValueProcessors then processItem(@options.attrValueProcessors, node.attributes[key], key) else node.attributes[key] | ||
processedKey = if @options.attrNameProcessors then processItem(@options.attrNameProcessors, key) else key | ||
if @options.mergeAttrs | ||
|
@@ -163,7 +163,7 @@ class exports.Parser extends events | |
# put children into <childkey> property and unfold chars if necessary | ||
if @options.explicitChildren and not @options.mergeAttrs and typeof obj is 'object' | ||
if not @options.preserveChildrenOrder | ||
node = {} | ||
node = Object.create(null) | ||
# separate attributes | ||
if @options.attrkey of obj | ||
node[@options.attrkey] = obj[@options.attrkey] | ||
|
@@ -181,7 +181,7 @@ class exports.Parser extends events | |
# append current node onto parent's <childKey> array | ||
s[@options.childkey] = s[@options.childkey] or [] | ||
# push a clone so that the node in the children array can receive the #name property while the original obj can do without it | ||
objClone = {} | ||
objClone = Object.create(null) | ||
for own key of obj | ||
objClone[key] = obj[key] | ||
s[@options.childkey].push objClone | ||
|
@@ -198,7 +198,7 @@ class exports.Parser extends events | |
if @options.explicitRoot | ||
# avoid circular references | ||
old = obj | ||
obj = {} | ||
obj = Object.create(null) | ||
obj[nodeName] = old | ||
|
||
@resultObject = obj | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi, it should be
Object.create({})
else prototype ofobj
is "null", then it may break should tests. For example, try to launch test on node-rest-client.