File tree Expand file tree Collapse file tree
packages/engine.io-client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1167,7 +1167,8 @@ export class Socket extends SocketWithUpgrade {
11671167 constructor ( uri ?: string , opts ?: SocketOptions ) ;
11681168 constructor ( opts : SocketOptions ) ;
11691169 constructor ( uri ?: string | SocketOptions , opts : SocketOptions = { } ) {
1170- const o = typeof uri === "object" ? uri : opts ;
1170+ const isOptionsOnly = typeof uri === "object" ;
1171+ const o = isOptionsOnly ? { ...uri } : { ...opts } ;
11711172
11721173 if (
11731174 ! o . transports ||
@@ -1178,6 +1179,9 @@ export class Socket extends SocketWithUpgrade {
11781179 . filter ( ( t ) => ! ! t ) ;
11791180 }
11801181
1181- super ( uri as string , o as BaseSocketOptions ) ;
1182+ super (
1183+ isOptionsOnly ? ( o as BaseSocketOptions ) : uri ,
1184+ o as BaseSocketOptions ,
1185+ ) ;
11821186 }
11831187}
Original file line number Diff line number Diff line change @@ -23,6 +23,19 @@ describe("Socket", function () {
2323 } ) ;
2424 } ) ;
2525
26+ it ( "should not mutate the caller's transports option" , ( ) => {
27+ const optsWithUri = { transports : [ "websocket" , "polling" ] } ;
28+ const optsWithoutUri = { transports : [ "polling" ] } ;
29+
30+ const socketWithUri = new Socket ( "http://localhost" , optsWithUri ) ;
31+ const socketWithoutUri = new Socket ( optsWithoutUri ) ;
32+
33+ expect ( optsWithUri . transports ) . to . eql ( [ "websocket" , "polling" ] ) ;
34+ expect ( optsWithoutUri . transports ) . to . eql ( [ "polling" ] ) ;
35+ socketWithUri . close ( ) ;
36+ socketWithoutUri . close ( ) ;
37+ } ) ;
38+
2639 it ( "throws an error when no transports are available" , ( done ) => {
2740 const socket = new Socket ( { transports : [ ] } ) ;
2841 let errorMessage = "" ;
You can’t perform that action at this time.
0 commit comments