Skip to content

Commit 1c220dd

Browse files
fix: allow integers as event names
This commit restores the possibility to use integers as event names, which was possible in Socket.IO v2.
1 parent 444520d commit 1c220dd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class Decoder extends Emitter {
245245
return typeof payload === "string" || typeof payload === "object";
246246
case PacketType.EVENT:
247247
case PacketType.BINARY_EVENT:
248-
return Array.isArray(payload) && typeof payload[0] === "string";
248+
return Array.isArray(payload) && payload.length > 0;
249249
case PacketType.ACK:
250250
case PacketType.BINARY_ACK:
251251
return Array.isArray(payload);

test/parser.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ describe("parser", () => {
4747
);
4848
});
4949

50+
it("encodes an event (with an integer as event name)", (done) => {
51+
helpers.test(
52+
{
53+
type: PacketType.EVENT,
54+
data: [1, "a", {}],
55+
nsp: "/",
56+
},
57+
done
58+
);
59+
});
60+
5061
it("encodes an event (with ack)", (done) => {
5162
helpers.test(
5263
{

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