diff --git a/src/utils.js b/src/utils.js index 9dc9e51..2ad6055 100644 --- a/src/utils.js +++ b/src/utils.js @@ -41,6 +41,7 @@ export function is_plain_object(thing) { return ( proto === Object.prototype || proto === null || + Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join('\0') === object_proto_names ); } diff --git a/test/test.js b/test/test.js index ebd4147..87c7ec3 100644 --- a/test/test.js +++ b/test/test.js @@ -9,6 +9,12 @@ class Custom { } } +const NullObject = (() => { + const C = function () {}; + C.prototype = Object.create(null); + return C; +})() + const node_version = +process.versions.node.split('.')[0]; const fixtures = { @@ -320,6 +326,21 @@ const fixtures = { }; })(Object.create(null)), + ((obj) => { + obj.self = obj; + return { + name: 'Object with null prototype class', + value: obj, + js: '(function(a){a.foo="bar";a.self=a;return a}({}))', + json: '[{"foo":1,"self":0},"bar"]', + validate: (value) => { + assert.is(value.foo, "bar") + assert.is(value.self, value); + + } + }; + })(Object.assign(new NullObject(), { foo: 'bar' })), + ((first, second) => { first.second = second; second.first = first;