mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
fix(msgpack): encode maps with null prototype (#4764)
* fix(msgpack): encode maps with null prototype * deno fmt * improve reusability
This commit is contained in:
parent
f4b0704d76
commit
52116b2dd6
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user