Remove user/pass support from irc://, support multiple channels

Other clients and specs explicitly don't support user:pass
This commit is contained in:
Pavel Djundik 2019-11-24 11:37:25 +02:00
parent ec85372132
commit 83f3fe772a
2 changed files with 40 additions and 76 deletions

View file

@ -35,27 +35,18 @@ export default (stringUri) => {
data.host = data.name = uri.hostname;
data.port = uri.port;
data.username = decodeURIComponent(uri.username);
data.password = decodeURIComponent(uri.password);
let channel = "";
if (uri.pathname.length > 1) {
channel = uri.pathname;
} else if (uri.hash.length > 1) {
channel = uri.hash;
channel = uri.pathname.substr(1); // Remove slash
}
if (channel) {
channel = channel.substr(1); // remove / or #
const index = channel.indexOf(",");
if (index > -1) {
channel = channel.substring(0, index);
}
if (uri.hash.length > 1) {
channel += uri.hash;
}
// We don't split channels or append # here because the connect window takes care of that
data.join = channel;
} catch (e) {
// do nothing on invalid uri

View file

@ -10,8 +10,6 @@ describe("parseIrcUri helper", function() {
name: "example.com",
host: "example.com",
port: "6667",
username: "",
password: "",
join: "",
});
});
@ -22,8 +20,6 @@ describe("parseIrcUri helper", function() {
name: "example.com",
host: "example.com",
port: "6697",
username: "",
password: "",
join: "",
});
});
@ -34,8 +30,6 @@ describe("parseIrcUri helper", function() {
name: "example.com",
host: "example.com",
port: "1337",
username: "",
password: "",
join: "",
});
});
@ -46,76 +40,55 @@ describe("parseIrcUri helper", function() {
name: "example.com",
host: "example.com",
port: "1337",
username: "",
password: "",
join: "",
});
});
it("should parse username, password and port", function() {
expect(parseIrcUri("ircs://user:password@example.com:1337")).to.deep.equal({
tls: true,
name: "example.com",
host: "example.com",
port: "1337",
username: "user",
password: "password",
join: "",
});
});
it("should parse channel from query", function() {
expect(parseIrcUri("ircs://example.com:1337/channel,channel2")).to.deep.equal({
tls: true,
name: "example.com",
host: "example.com",
port: "1337",
username: "",
password: "",
join: "channel",
});
});
it("should parse channel from hash", function() {
const obj = {
tls: true,
name: "example.com",
host: "example.com",
port: "1337",
username: "",
password: "",
join: "channel",
};
expect(parseIrcUri("ircs://example.com:1337#channel,channel2")).to.deep.equal(obj);
expect(parseIrcUri("ircs://example.com:1337/#channel,channel2")).to.deep.equal(obj);
});
it("accepts query over hash", function() {
expect(parseIrcUri("ircs://example.com:1337/channel#channel2")).to.deep.equal({
tls: true,
name: "example.com",
host: "example.com",
port: "1337",
username: "",
password: "",
join: "channel",
});
});
it("should not parse invalid port", function() {
expect(parseIrcUri("ircs://example.com:lol")).to.deep.equal({});
});
it("should not parse plus in port", function() {
expect(parseIrcUri("irc://example.com:+6697")).to.deep.equal({});
});
it("should not channel on empty query and hash", function() {
expect(parseIrcUri("irc://example.com/#")).to.deep.equal({
const obj = {
tls: false,
name: "example.com",
host: "example.com",
port: "6667",
username: "",
password: "",
join: "",
});
};
expect(parseIrcUri("irc://example.com#")).to.deep.equal(obj);
expect(parseIrcUri("irc://example.com/")).to.deep.equal(obj);
expect(parseIrcUri("irc://example.com/#")).to.deep.equal(obj);
});
it("should parse multiple channels", function() {
const obj = {
tls: true,
name: "example.com",
host: "example.com",
port: "1337",
join: "#channel,channel2",
};
expect(parseIrcUri("ircs://example.com:1337#channel,channel2")).to.deep.equal(obj);
expect(parseIrcUri("ircs://example.com:1337/#channel,channel2")).to.deep.equal(obj);
obj.join = "channel,channel2";
expect(parseIrcUri("ircs://example.com:1337/channel,channel2")).to.deep.equal(obj);
obj.join = "chan,#chan2,#chan3";
expect(parseIrcUri("ircs://example.com:1337/chan,#chan2,#chan3")).to.deep.equal(obj);
obj.join = "&chan,@chan2,#chan3";
expect(parseIrcUri("ircs://example.com:1337/&chan,@chan2,#chan3")).to.deep.equal(obj);
// URL() drops empty hash
obj.join = "chan";
expect(parseIrcUri("ircs://example.com:1337/chan#")).to.deep.equal(obj);
});
});