mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-09 15:08:12 -05:00
refactor(sio): use URL constructor instead of url.parse()
Related: https://github.com/socketio/socket.io/issues/5377
This commit is contained in:
@@ -267,16 +267,7 @@ export class Client<
|
||||
* @private
|
||||
*/
|
||||
private ondecoded(packet: Packet): void {
|
||||
let namespace: string;
|
||||
let authPayload: Record<string, unknown>;
|
||||
if (this.conn.protocol === 3) {
|
||||
const parsed = url.parse(packet.nsp, true);
|
||||
namespace = parsed.pathname!;
|
||||
authPayload = parsed.query;
|
||||
} else {
|
||||
namespace = packet.nsp;
|
||||
authPayload = packet.data;
|
||||
}
|
||||
const { namespace, authPayload } = this._parseNamespace(packet);
|
||||
const socket = this.nsps.get(namespace);
|
||||
|
||||
if (!socket && packet.type === PacketType.CONNECT) {
|
||||
@@ -295,6 +286,20 @@ export class Client<
|
||||
}
|
||||
}
|
||||
|
||||
private _parseNamespace(packet: Packet) {
|
||||
if (this.conn.protocol !== 3) {
|
||||
return {
|
||||
namespace: packet.nsp,
|
||||
authPayload: packet.data,
|
||||
};
|
||||
}
|
||||
const url = new URL(packet.nsp, "https://socket.io");
|
||||
return {
|
||||
namespace: url.pathname,
|
||||
authPayload: Object.fromEntries(url.searchParams.entries()),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an error.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user