mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-13 00:48:12 -05:00
If a client was in the process of receiving some binary attachments
when the connection was abruptly closed, then the manager would call
`decoder.destroy()` ([1]) but was then stuck in a "parse error" loop
upon reconnection (since it expected a binary attachment and not a
CONNECT packet).
[1]: a1c528b089/lib/manager.ts (L520)
88 lines
2.0 KiB
JavaScript
88 lines
2.0 KiB
JavaScript
const { PacketType, Decoder, Encoder } = require("..");
|
|
const expect = require("expect.js");
|
|
const helpers = require("./helpers.js");
|
|
const encoder = new Encoder();
|
|
|
|
describe("ArrayBuffer", () => {
|
|
it("encodes an ArrayBuffer", () => {
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
data: ["a", new ArrayBuffer(2)],
|
|
id: 0,
|
|
nsp: "/",
|
|
};
|
|
return helpers.test_bin(packet);
|
|
});
|
|
|
|
it("encodes an ArrayBuffer into an object with a null prototype", () => {
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
data: [
|
|
"a",
|
|
Object.create(null, {
|
|
array: { value: new ArrayBuffer(2), enumerable: true },
|
|
}),
|
|
],
|
|
id: 0,
|
|
nsp: "/",
|
|
};
|
|
return helpers.test_bin(packet);
|
|
});
|
|
|
|
it("encodes a TypedArray", () => {
|
|
const array = new Uint8Array(5);
|
|
for (let i = 0; i < array.length; i++) array[i] = i;
|
|
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
data: ["a", array],
|
|
id: 0,
|
|
nsp: "/",
|
|
};
|
|
return helpers.test_bin(packet);
|
|
});
|
|
|
|
it("encodes ArrayBuffers deep in JSON", () => {
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
data: [
|
|
"a",
|
|
{
|
|
a: "hi",
|
|
b: { why: new ArrayBuffer(3) },
|
|
c: { a: "bye", b: { a: new ArrayBuffer(6) } },
|
|
},
|
|
],
|
|
id: 999,
|
|
nsp: "/deep",
|
|
};
|
|
return helpers.test_bin(packet);
|
|
});
|
|
|
|
it("encodes deep binary JSON with null values", () => {
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
data: ["a", { a: "b", c: 4, e: { g: null }, h: new ArrayBuffer(9) }],
|
|
nsp: "/",
|
|
id: 600,
|
|
};
|
|
return helpers.test_bin(packet);
|
|
});
|
|
|
|
it("should not modify the input packet", () => {
|
|
const packet = {
|
|
type: PacketType.EVENT,
|
|
nsp: "/",
|
|
data: ["a", Uint8Array.of(1, 2, 3), Uint8Array.of(4, 5, 6)],
|
|
};
|
|
|
|
encoder.encode(packet);
|
|
|
|
expect(packet).to.eql({
|
|
type: PacketType.EVENT,
|
|
nsp: "/",
|
|
data: ["a", Uint8Array.of(1, 2, 3), Uint8Array.of(4, 5, 6)],
|
|
});
|
|
});
|
|
});
|