Skip to content

Commit 7f6b262

Browse files
authored
fix: allow objects with a null prototype in binary packets (#114)
1 parent 8e8346b commit 7f6b262

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/binary.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _deconstructPacket(data, buffers) {
3333
} else if (typeof data === "object" && !(data instanceof Date)) {
3434
const newData = {};
3535
for (const key in data) {
36-
if (data.hasOwnProperty(key)) {
36+
if (Object.prototype.hasOwnProperty.call(data, key)) {
3737
newData[key] = _deconstructPacket(data[key], buffers);
3838
}
3939
}
@@ -68,7 +68,7 @@ function _reconstructPacket(data, buffers) {
6868
}
6969
} else if (typeof data === "object") {
7070
for (const key in data) {
71-
if (data.hasOwnProperty(key)) {
71+
if (Object.prototype.hasOwnProperty.call(data, key)) {
7272
data[key] = _reconstructPacket(data[key], buffers);
7373
}
7474
}

test/arraybuffer.js

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ describe("parser", () => {
1414
helpers.test_bin(packet, done);
1515
});
1616

17+
it("encodes an ArrayBuffer into an object with a null prototype", (done) => {
18+
const packet = {
19+
type: PacketType.EVENT,
20+
data: [
21+
"a",
22+
Object.create(null, {
23+
array: { value: new ArrayBuffer(2), enumerable: true },
24+
}),
25+
],
26+
id: 0,
27+
nsp: "/",
28+
};
29+
helpers.test_bin(packet, done);
30+
});
31+
1732
it("encodes a TypedArray", (done) => {
1833
const array = new Uint8Array(5);
1934
for (let i = 0; i < array.length; i++) array[i] = i;

0 commit comments

Comments
 (0)