Skip to content

fix(sio-client): default to https for a URL with no scheme in Node.js and React Native - #5626

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-url-no-scheme
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/sio-client-url-no-scheme

Conversation

@mark1russell7

Copy link
Copy Markdown

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

When there is no location object, loc is false, so the check "undefined" !== typeof loc is always true, and url("example.com:3000") gives "undefined//example.com:3000". The fallback to https:// never runs.

New behavior

The check is if (loc), so the fallback to https:// runs when there is no location object.

A test is added in test/url.ts ("works with no protocol and no location (Node.js and React Native)"). It is skipped when a location object exists (the browser tests).

The tests ran in GitHub Actions (Node.js 24.22.2 on Linux): the new tests with the lib folder of upstream main (before), then with this change (after), then npm test of socket.io-client with this change:

upstream main: f97d51a810d4f266122eb99bb6c083cd383638f0
== F0061 (fix/sio-client-url-no-scheme)
  commit c7cad619, base behind
  F0061-before:  0 passing (10ms)  1 failing  1) works with no protocol and no location (Node.js and React Native); 1) url; exit=1
  F0061-after:  1 passing (7ms)  exit=0
  npm test:  116 passing (7s)  exit=0

The failures before the change:

  1 failing

  1) url
       works with no protocol and no location (Node.js and React Native):
     Error: expected '' to equal 'https'
      at Assertion.assert (/home/runner/work/wirelab/wirelab/repros/fix-tests/socket.io-client/group-2/socket.io/node_modules/expect.js/index.js:96:13)

Other information (e.g. related issues)

Closes #5620

This PR was prepared with AI assistance (Claude). The tests above were run before and after the change, with the results above.

🤖 Generated with Claude Code

… and React Native

Without a global location object, loc was false, so the check
"undefined" !== typeof loc was always true, and a URL with no scheme
became "undefined//host" instead of "https://host".
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.

[socket.io-client] A URL with no scheme gives "undefined//host" in Node.js and React Native

1 participant