Properly handle port in irc:// URLs

This commit is contained in:
Simon Ser 2021-11-16 11:52:38 +01:00
parent a0b250df3f
commit 82e5a2795d

View file

@ -58,6 +58,24 @@ function parseQueryString() {
return params; return params;
} }
function splitHostPort(str) {
let host = str;
let port = null;
// Literal IPv6 addresses contain colons and are enclosed in square brackets
let i = str.lastIndexOf(":");
if (i > 0 && !str.endsWith("]")) {
host = str.slice(0, i);
port = parseInt(str.slice(i + 1), 10);
}
if (host.startsWith("[") && host.endsWith("]")) {
host = host.slice(1, host.length - 1);
}
return { host, port };
}
function fillConnectParams(params) { function fillConnectParams(params) {
let host = window.location.host || "localhost:8080"; let host = window.location.host || "localhost:8080";
let proto = "wss:"; let proto = "wss:";
@ -969,11 +987,13 @@ export default class App extends Component {
return false; return false;
} }
let { host, port } = splitHostPort(url.host);
let serverID; let serverID;
if (!url.host) { if (!url.host) {
serverID = State.getActiveServerID(this.state); serverID = State.getActiveServerID(this.state);
} else { } else {
let bouncerNetID = this.findBouncerNetIDByHost(url.host); let bouncerNetID = this.findBouncerNetIDByHost(host);
if (!bouncerNetID) { if (!bouncerNetID) {
// Open dialog to create network if bouncer // Open dialog to create network if bouncer
let client = this.clients.values().next().value; let client = this.clients.values().next().value;
@ -981,7 +1001,10 @@ export default class App extends Component {
return false; return false;
} }
let params = { host: url.host }; let params = { host };
if (typeof port === "number") {
params.port = port;
}
this.openDialog("network", { params, autojoin: url.entity }); this.openDialog("network", { params, autojoin: url.entity });
return true; return true;
} }