Skip to content

Commit 0916568

Browse files
committed
Let browser handle parsing of URLs before relaying
We don't want to assign a path directly to url.pathname that contains a search query, since this causes '?' at the beginning of the query to be URL-encoded to '%3F'. Instead we build a new URL-string that can be parsed correctly by the URL-class.
1 parent b25675e commit 0916568

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/ui.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,18 +1052,23 @@ const UI = {
10521052
let url;
10531053

10541054
if (host) {
1055-
url = new URL("https://" + host);
1055+
let _url = new URL("https://" + host);
10561056

1057-
url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:';
10581057
if (port) {
1059-
url.port = port;
1058+
_url.port = port;
10601059
}
1061-
url.pathname = '/' + path;
1060+
1061+
// "./" is needed in case path contains more than one leading
1062+
// slash, in which case URL() would interpret it as a host
1063+
// name.
1064+
url = new URL("./" + path, _url);
1065+
1066+
url.protocol = UI.getSetting('encrypt') ? 'wss:' : 'ws:';
10621067
} else {
10631068
// Current (May 2024) browsers support relative WebSocket
10641069
// URLs natively, but we need to support older browsers for
10651070
// some time.
1066-
url = new URL(path, location.href);
1071+
url = new URL("./" + path, location.href);
10671072
url.protocol = (window.location.protocol === "https:") ? 'wss:' : 'ws:';
10681073
}
10691074

0 commit comments

Comments
 (0)