From c7cad6193a90ada6257302433c704de6b4b429f4 Mon Sep 17 00:00:00 2001 From: Mark Russell <39885340+mark1russell7@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:34:50 -0500 Subject: [PATCH] fix(sio-client): default to https for a URL with no scheme in Node.js 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". --- packages/socket.io-client/lib/url.ts | 2 +- packages/socket.io-client/test/url.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/socket.io-client/lib/url.ts b/packages/socket.io-client/lib/url.ts index c84bef16f4..0a2b74e566 100644 --- a/packages/socket.io-client/lib/url.ts +++ b/packages/socket.io-client/lib/url.ts @@ -59,7 +59,7 @@ export function url( if (!/^(https?|wss?):\/\//.test(uri)) { debug("protocol-less url %s", uri); - if ("undefined" !== typeof loc) { + if (loc) { uri = loc.protocol + "//" + uri; } else { uri = "https://" + uri; diff --git a/packages/socket.io-client/test/url.ts b/packages/socket.io-client/test/url.ts index 03df463d47..565aefaf4d 100644 --- a/packages/socket.io-client/test/url.ts +++ b/packages/socket.io-client/test/url.ts @@ -88,4 +88,15 @@ describe("url", () => { expect(parsed.id).to.be("https://woot.com:443/some-path"); expect(parsed.path).to.be("/some-namespace"); }); + + it("works with no protocol and no location (Node.js and React Native)", function () { + if (typeof location !== "undefined") { + return this.skip(); + } + const parsed = url("woot.com:3000"); + expect(parsed.protocol).to.be("https"); + expect(parsed.host).to.be("woot.com"); + expect(parsed.port).to.be("3000"); + expect(parsed.id).to.be("https://woot.com:3000"); + }); });