From af5c6bb5dca6f0248c153aa87e25bddfc515ff6e Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 11 Dec 2020 11:56:49 -0800 Subject: [PATCH] Do not use Object.create(null) Reverts 032fbaf5f0b98fce70c8cc380e0d05177a9c9073 Turns out this was a breaking change, because people relied on doing `config.hasOwnProperty(blah)` with ini-returned objects. Will re-land 032fbaf5f0b98fce70c8cc380e0d05177a9c9073 on a v2 release. --- ini.js | 10 +++++----- test/proto.js | 40 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ini.js b/ini.js index f8107ca..b576f08 100644 --- a/ini.js +++ b/ini.js @@ -18,7 +18,7 @@ function encode (obj, opt) { whitespace: false, } } else { - opt = opt || Object.create(null) + opt = opt || {} opt.whitespace = opt.whitespace === true } @@ -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 @@ -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]) @@ -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) diff --git a/test/proto.js b/test/proto.js index db55233..6bab1bf 100644 --- a/test/proto.js +++ b/test/proto.js @@ -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)