Skip to content

Commit

Permalink
fix: allow integers as event names
Browse files Browse the repository at this point in the history
This commit restores the possibility to use integers as event names,
which was possible in Socket.IO v2.
  • Loading branch information
darrachequesne committed Jan 15, 2021
1 parent 444520d commit 1c220dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class Decoder extends Emitter {
return typeof payload === "string" || typeof payload === "object";
case PacketType.EVENT:
case PacketType.BINARY_EVENT:
return Array.isArray(payload) && typeof payload[0] === "string";
return Array.isArray(payload) && payload.length > 0;
case PacketType.ACK:
case PacketType.BINARY_ACK:
return Array.isArray(payload);
Expand Down
11 changes: 11 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe("parser", () => {
);
});

it("encodes an event (with an integer as event name)", (done) => {
helpers.test(
{
type: PacketType.EVENT,
data: [1, "a", {}],
nsp: "/",
},
done
);
});

it("encodes an event (with ack)", (done) => {
helpers.test(
{
Expand Down

0 comments on commit 1c220dd

Please sign in to comment.