From 83f3fe772ae1c3ad479c78d8cba35af627e9d743 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 24 Nov 2019 11:37:25 +0200 Subject: [PATCH] Remove user/pass support from irc://, support multiple channels Other clients and specs explicitly don't support user:pass --- client/js/helpers/parseIrcUri.js | 17 ++--- test/client/js/helpers/parseIrcUri.js | 99 ++++++++++----------------- 2 files changed, 40 insertions(+), 76 deletions(-) diff --git a/client/js/helpers/parseIrcUri.js b/client/js/helpers/parseIrcUri.js index 8bb3b64b..9ed09073 100644 --- a/client/js/helpers/parseIrcUri.js +++ b/client/js/helpers/parseIrcUri.js @@ -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 diff --git a/test/client/js/helpers/parseIrcUri.js b/test/client/js/helpers/parseIrcUri.js index e69c3012..968cf103 100644 --- a/test/client/js/helpers/parseIrcUri.js +++ b/test/client/js/helpers/parseIrcUri.js @@ -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); }); });