Skip to content

[fix] Do not modify the url.URL object passed to the constructor - #2353

Open
simonkundrik wants to merge 2 commits into
websockets:masterfrom
simonkundrik:fix/do-not-modify-url-object
Open

simonkundrik wants to merge 2 commits into
websockets:masterfrom
simonkundrik:fix/do-not-modify-url-object

Conversation

@simonkundrik

Copy link
Copy Markdown
Contributor

new WebSocket(url) changes url.protocol from http: to ws: (and from https: to wss:) on the url.URL object it is given, so code that keeps using the URL afterwards sees a different one:

const url = new URL('http://localhost/foo');
const ws = new WebSocket(url);

console.log(url.href); // 'ws://localhost/foo'

This parses a copy of the URL object instead, as is already done for strings. I added a test, which fails on master. npm test passes and eslint and prettier are clean.

The protocol of an `http:` or `https:` URL object was changed to `ws:` or
`wss:` in place, so the object the caller passed in was modified. Parse
a copy of it instead, as is done for strings.
Comment thread test/websocket.test.js Resolved
Comment thread lib/websocket.js Resolved
Parse URL objects with new URL(address) and use the lookup option in the
test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants