Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9db473

Browse files
fix: ensure reserved events cannot be used as event names
1 parent6a5a004 commitd9db473

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

‎lib/index.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import debugModule from "debug"; // debug()
55

66
constdebug=debugModule("socket.io-parser");// debug()
77

8+
/**
9+
* These strings must not be used as event names, as they have a special meaning.
10+
*/
11+
constRESERVED_EVENTS=[
12+
"connect",// used on the client side
13+
"connect_error",// used on the client side
14+
"disconnect",// used on both sides
15+
"disconnecting",// used on the server side
16+
"newListener",// used by the Node.js EventEmitter
17+
"removeListener",// used by the Node.js EventEmitter
18+
];
19+
820
/**
921
* Protocol version.
1022
*
@@ -277,7 +289,9 @@ export class Decoder extends Emitter<{}, {}, DecoderReservedEvents> {
277289
casePacketType.BINARY_EVENT:
278290
return(
279291
Array.isArray(payload)&&
280-
(typeofpayload[0]==="string"||typeofpayload[0]==="number")
292+
(typeofpayload[0]==="number"||
293+
(typeofpayload[0]==="string"&&
294+
RESERVED_EVENTS.indexOf(payload[0])===-1))
281295
);
282296
casePacketType.ACK:
283297
casePacketType.BINARY_ACK:

‎test/parser.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ describe("socket.io-parser", () => {
121121
isInvalidPayload('2[{"toString":"foo"}]');
122122
isInvalidPayload('2[true,"foo"]');
123123
isInvalidPayload('2[null,"bar"]');
124+
isInvalidPayload('2["connect"]');
125+
isInvalidPayload('2["disconnect","123"]');
124126

125127
expect(()=>newDecoder().add("999")).to.throwException(
126128
/^unknownpackettype9$/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp