Skip to content

Commit ad3a297

Browse files
committedApr 27, 2023
refactor: extract function for key check
1 parent d486007 commit ad3a297

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed
 

‎src/parser.coffee

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ defaults = require('./defaults').defaults
1111
isEmpty = (thing) ->
1212
return typeof thing is "object" && thing? && Object.keys(thing).length is 0
1313

14+
isValidKey = (key) ->
15+
return key != '__proto__' && key != 'constructor' && key != 'prototype'
16+
1417
processItem = (processors, item, key) ->
1518
item = process(item, key) for process in processors
1619
return item
@@ -52,8 +55,7 @@ class exports.Parser extends events
5255
@emit err
5356

5457
assignOrPush: (obj, key, newValue) =>
55-
return if key == '__proto__'
56-
return if key == 'constructor'
58+
return if not isValidKey(key)
5759
if key not of obj
5860
if not @options.explicitArray
5961
obj[key] = newValue
@@ -112,9 +114,10 @@ class exports.Parser extends events
112114
obj[attrkey] = {}
113115
newValue = if @options.attrValueProcessors then processItem(@options.attrValueProcessors, node.attributes[key], key) else node.attributes[key]
114116
processedKey = if @options.attrNameProcessors then processItem(@options.attrNameProcessors, key) else key
115-
if @options.mergeAttrs
116-
@assignOrPush obj, processedKey, newValue
117-
else
117+
if isValidKey(processedKey)
118+
if @options.mergeAttrs
119+
@assignOrPush obj, processedKey, newValue
120+
else
118121
@assignOrPush obj[attrkey], processedKey, newValue
119122

120123
# need a place to store the node name

0 commit comments

Comments
 (0)
Please sign in to comment.