Skip to content

Commit

Permalink
Do not use Object.create(null)
Browse files Browse the repository at this point in the history
Reverts 032fbaf

Turns out this was a breaking change, because people relied on doing
`config.hasOwnProperty(blah)` with ini-returned objects.

Will re-land 032fbaf on a v2 release.
  • Loading branch information
isaacs committed Dec 11, 2020
1 parent 8b648a1 commit af5c6bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function encode (obj, opt) {
whitespace: false,
}
} else {
opt = opt || Object.create(null)
opt = opt || {}
opt.whitespace = opt.whitespace === true
}

Expand Down Expand Up @@ -65,7 +65,7 @@ function dotSplit (str) {
}

function decode (str) {
var out = Object.create(null)
var out = {}
var p = out
var section = null
// section |key = value
Expand All @@ -83,10 +83,10 @@ function decode (str) {
if (section === '__proto__') {
// not allowed
// keep parsing the section, but don't attach it.
p = Object.create(null)
p = {}
return
}
p = out[section] = out[section] || Object.create(null)
p = out[section] = out[section] || {}
return
}
var key = unsafe(match[2])
Expand Down Expand Up @@ -136,7 +136,7 @@ function decode (str) {
if (part === '__proto__')
return
if (!p[part] || typeof p[part] !== 'object')
p[part] = Object.create(null)
p[part] = {}
p = p[part]
})
if (p === out && nl === l)
Expand Down
40 changes: 20 additions & 20 deletions test/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ foo = asdfasdf

var res = ini.parse(data)

t.deepEqual(res, Object.assign(Object.create(null), {
t.deepEqual(res, {
'constructor.prototype.foo': 'asdfasdf',
foo: 'baz',
other: Object.assign(Object.create(null), {
other: {
foo: 'asdf',
}),
kid: Object.assign(Object.create(null), {
foo: Object.assign(Object.create(null), {
},
kid: {
foo: {
foo: 'kid',
}),
}),
arrproto: Object.assign(Object.create(null), {
},
},
arrproto: {
hello: 'snyk',
thanks: true,
}),
ctor: Object.assign(Object.create(null), {
constructor: Object.assign(Object.create(null), {
prototype: Object.assign(Object.create(null), {
},
ctor: {
constructor: {
prototype: {
foo: 'asdfasdf',
}),
}),
}),
}))
t.equal(res.__proto__, undefined)
t.equal(res.kid.__proto__, undefined)
t.equal(res.kid.foo.__proto__, undefined)
t.equal(res.arrproto.__proto__, undefined)
},
},
},
})
t.equal(res.__proto__, Object.prototype)
t.equal(res.kid.__proto__, Object.prototype)
t.equal(res.kid.foo.__proto__, Object.prototype)
t.equal(res.arrproto.__proto__, Object.prototype)
t.equal(Object.prototype.foo, undefined)
t.equal(Object.prototype[0], undefined)
t.equal(Object.prototype['0'], undefined)
Expand Down

0 comments on commit af5c6bb

Please sign in to comment.