diff --git a/msgpack/encode.ts b/msgpack/encode.ts index cee2bac721a8..dd89a61de339 100644 --- a/msgpack/encode.ts +++ b/msgpack/encode.ts @@ -249,7 +249,9 @@ function encodeSlice(object: ValueType, byteParts: Uint8Array[]) { } // If object is a plain object - if (Object.getPrototypeOf(object) === Object.prototype) { + const prototype = Object.getPrototypeOf(object); + + if (prototype === null || prototype === Object.prototype) { const numKeys = Object.keys(object).length; if (numKeys < FOUR_BITS) { // fixarray diff --git a/msgpack/encode_test.ts b/msgpack/encode_test.ts index a80949445c73..c808ed19c3b0 100644 --- a/msgpack/encode_test.ts +++ b/msgpack/encode_test.ts @@ -156,6 +156,9 @@ Deno.test("encode() handles maps", () => { const map0 = {}; assertEquals(decode(encode(map0)), map0); + const mapNull = Object.create(null); + assertEquals(decode(encode(mapNull)), mapNull); + const map1 = { "a": 0, "b": 2, "c": "three", "d": null }; assertEquals(decode(encode(map1)), map1);