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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 15 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy