Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows [Object: null prototype] in binary packet #114

Merged
merged 1 commit into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/binary.ts
Expand Up @@ -33,7 +33,7 @@ function _deconstructPacket(data, buffers) {
} else if (typeof data === "object" && !(data instanceof Date)) {
const newData = {};
for (const key in data) {
if (data.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
newData[key] = _deconstructPacket(data[key], buffers);
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@ function _reconstructPacket(data, buffers) {
}
} else if (typeof data === "object") {
for (const key in data) {
if (data.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
data[key] = _reconstructPacket(data[key], buffers);
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/arraybuffer.js
Expand Up @@ -14,6 +14,21 @@ describe("parser", () => {
helpers.test_bin(packet, done);
});

it("encodes an ArrayBuffer into an object with a null prototype", (done) => {
const packet = {
type: PacketType.EVENT,
data: [
"a",
Object.create(null, {
array: { value: new ArrayBuffer(2), enumerable: true },
}),
],
id: 0,
nsp: "/",
};
helpers.test_bin(packet, done);
});

it("encodes a TypedArray", (done) => {
const array = new Uint8Array(5);
for (let i = 0; i < array.length; i++) array[i] = i;
Expand Down