Skip to content

Commit af5c6bb

Browse files
committed
Do not use Object.create(null)
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.
1 parent 8b648a1 commit af5c6bb

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

ini.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function encode (obj, opt) {
1818
whitespace: false,
1919
}
2020
} else {
21-
opt = opt || Object.create(null)
21+
opt = opt || {}
2222
opt.whitespace = opt.whitespace === true
2323
}
2424

@@ -65,7 +65,7 @@ function dotSplit (str) {
6565
}
6666

6767
function decode (str) {
68-
var out = Object.create(null)
68+
var out = {}
6969
var p = out
7070
var section = null
7171
// section |key = value
@@ -83,10 +83,10 @@ function decode (str) {
8383
if (section === '__proto__') {
8484
// not allowed
8585
// keep parsing the section, but don't attach it.
86-
p = Object.create(null)
86+
p = {}
8787
return
8888
}
89-
p = out[section] = out[section] || Object.create(null)
89+
p = out[section] = out[section] || {}
9090
return
9191
}
9292
var key = unsafe(match[2])
@@ -136,7 +136,7 @@ function decode (str) {
136136
if (part === '__proto__')
137137
return
138138
if (!p[part] || typeof p[part] !== 'object')
139-
p[part] = Object.create(null)
139+
p[part] = {}
140140
p = p[part]
141141
})
142142
if (p === out && nl === l)

test/proto.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@ foo = asdfasdf
2323

2424
var res = ini.parse(data)
2525

26-
t.deepEqual(res, Object.assign(Object.create(null), {
26+
t.deepEqual(res, {
2727
'constructor.prototype.foo': 'asdfasdf',
2828
foo: 'baz',
29-
other: Object.assign(Object.create(null), {
29+
other: {
3030
foo: 'asdf',
31-
}),
32-
kid: Object.assign(Object.create(null), {
33-
foo: Object.assign(Object.create(null), {
31+
},
32+
kid: {
33+
foo: {
3434
foo: 'kid',
35-
}),
36-
}),
37-
arrproto: Object.assign(Object.create(null), {
35+
},
36+
},
37+
arrproto: {
3838
hello: 'snyk',
3939
thanks: true,
40-
}),
41-
ctor: Object.assign(Object.create(null), {
42-
constructor: Object.assign(Object.create(null), {
43-
prototype: Object.assign(Object.create(null), {
40+
},
41+
ctor: {
42+
constructor: {
43+
prototype: {
4444
foo: 'asdfasdf',
45-
}),
46-
}),
47-
}),
48-
}))
49-
t.equal(res.__proto__, undefined)
50-
t.equal(res.kid.__proto__, undefined)
51-
t.equal(res.kid.foo.__proto__, undefined)
52-
t.equal(res.arrproto.__proto__, undefined)
45+
},
46+
},
47+
},
48+
})
49+
t.equal(res.__proto__, Object.prototype)
50+
t.equal(res.kid.__proto__, Object.prototype)
51+
t.equal(res.kid.foo.__proto__, Object.prototype)
52+
t.equal(res.arrproto.__proto__, Object.prototype)
5353
t.equal(Object.prototype.foo, undefined)
5454
t.equal(Object.prototype[0], undefined)
5555
t.equal(Object.prototype['0'], undefined)

0 commit comments

Comments
 (0)