Take 2
This commit is contained in:
parent
9d3ce5fa6d
commit
e58e9186f8
2 changed files with 10 additions and 8 deletions
|
|
@ -19,7 +19,6 @@ module.exports = function(string) {
|
|||
for (var j = 0; j < levels.length; j++) {
|
||||
var level = levels[j], nextLevel = levels[j + 1]
|
||||
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10))
|
||||
var isValue = j === levels.length - 1
|
||||
if (level === "") {
|
||||
var key = levels.slice(0, j).join()
|
||||
if (counters[key] == null) {
|
||||
|
|
@ -29,15 +28,15 @@ module.exports = function(string) {
|
|||
}
|
||||
// Disallow direct prototype pollution
|
||||
else if (level === "__proto__") break
|
||||
if (isValue) cursor[level] = value
|
||||
if (j === levels.length - 1) cursor[level] = value
|
||||
else {
|
||||
// Read own properties exclusively to disallow indirect
|
||||
// prototype pollution
|
||||
value = Object.getOwnPropertyDescriptor(cursor, level)
|
||||
if (value != null) value = value.value
|
||||
if (value == null) value = cursor[level] = isNumber ? [] : {}
|
||||
var desc = Object.getOwnPropertyDescriptor(cursor, level)
|
||||
if (desc != null) desc = desc.value
|
||||
if (desc == null) cursor[level] = desc = isNumber ? [] : {}
|
||||
cursor = desc
|
||||
}
|
||||
cursor = value
|
||||
}
|
||||
}
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue