fix(engine.io-client): prevent mutation of user-provided options#5471
Open
idirdev wants to merge 1 commit intosocketio:mainfrom
Open
fix(engine.io-client): prevent mutation of user-provided options#5471idirdev wants to merge 1 commit intosocketio:mainfrom
idirdev wants to merge 1 commit intosocketio:mainfrom
Conversation
The Socket constructor was directly referencing the caller's options object, causing the transports array to be replaced from string names to transport constructor classes. This shallow-clones the options before processing so the original object remains untouched. Fixes socketio#5462
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When creating a socket with
io(url, options), thetransportsarray in the user-provided options object is mutated from string names (["websocket", "polling"]) to transport constructor classes ([class WS, class XHR]).This is unexpected behavior — the caller's options object should remain untouched after being passed to
io().Root cause
In
packages/engine.io-client/lib/socket.ts, theSocketconstructor assignsodirectly to the caller's options reference:Then
o.transportsis reassigned with mapped constructor classes, which mutates the original object.Fix
Shallow-clone the options before processing:
This ensures modifications stay internal and the caller's object is never touched.
Test
Added a regression test in
packages/engine.io-client/test/socket.jsthat verifiesoptions.transportsremains unchanged after constructing aSocket.Fixes #5462