Skip to content

Commit d652463

Browse files
refactor: use URL constructor instead of url.parse()
1 parent d88f3f4 commit d652463

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

packages/socket.io/lib/client.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,7 @@ export class Client<
267267
* @private
268268
*/
269269
private ondecoded(packet: Packet): void {
270-
let namespace: string;
271-
let authPayload: Record<string, unknown>;
272-
if (this.conn.protocol === 3) {
273-
const parsed = url.parse(packet.nsp, true);
274-
namespace = parsed.pathname!;
275-
authPayload = parsed.query;
276-
} else {
277-
namespace = packet.nsp;
278-
authPayload = packet.data;
279-
}
270+
const { namespace, authPayload } = this._parseNamespace(packet);
280271
const socket = this.nsps.get(namespace);
281272

282273
if (!socket && packet.type === PacketType.CONNECT) {
@@ -295,6 +286,20 @@ export class Client<
295286
}
296287
}
297288

289+
private _parseNamespace(packet: Packet) {
290+
if (this.conn.protocol !== 3) {
291+
return {
292+
namespace: packet.nsp,
293+
authPayload: packet.data,
294+
};
295+
}
296+
const url = new URL(packet.nsp, "https://socket.io");
297+
return {
298+
namespace: url.pathname,
299+
authPayload: Object.fromEntries(url.searchParams.entries()),
300+
};
301+
}
302+
298303
/**
299304
* Handles an error.
300305
*

0 commit comments

Comments
 (0)