diff --git a/js/lib/connection-xpcom.js b/js/lib/connection-xpcom.js --- a/js/lib/connection-xpcom.js +++ b/js/lib/connection-xpcom.js @@ -229,6 +229,14 @@ this.host = host.toLowerCase(); this.port = port; + /* The APIs below want either host:port or host and port seperately. For + * the combined case, we must preserve the square brackets around IPv6 + * literals. For the split case, we must strip them. + */ + var hostPort = host + ":" + port; + if (host[0] == '[' && host[host.length - 1] == ']') + host = host.substr(1, host.length - 2); + if (typeof config != "object") config = {}; @@ -259,9 +267,9 @@ * force no proxy. Other values will get default treatment. */ if (config.proxy == "http") - proxyInfo = getProxyFor("http://" + host + ":" + port); + proxyInfo = getProxyFor("http://" + hostPort); else if (config.proxy != "none") - proxyInfo = getProxyFor("irc://" + host + ":" + port); + proxyInfo = getProxyFor("irc://" + hostPort); /* Since the proxy info is opaque, we need to check that we got * something for our HTTP proxy - we can't just check proxyInfo.type. @@ -270,7 +278,7 @@ } else { - proxyInfo = getProxyFor("irc://" + host + ":" + port); + proxyInfo = getProxyFor("irc://" + hostPort); } if (proxyInfo && ("type" in proxyInfo) && (proxyInfo.type == "unknown")) @@ -364,7 +372,7 @@ // Bootstrap the connection if we're proxying via an HTTP proxy. if (usingHTTPCONNECT) { - this.sendData("CONNECT " + host + ":" + port + " HTTP/1.1\r\n\r\n"); + this.sendData("CONNECT " + hostPort + " HTTP/1.1\r\n\r\n"); } return true; diff --git a/js/lib/irc.js b/js/lib/irc.js --- a/js/lib/irc.js +++ b/js/lib/irc.js @@ -3576,24 +3576,18 @@ var rest = arrayHasElementAt(ary, 2) ? ary[2] : ""; /* split into server (or network) / port */ - ary = host.match(/^([^\:]+)(\:\d+)?$/); + ary = host.match(/^([^\:]+|\[[^\]]+\])(\:\d+)?$/i); if (!ary) { dd("parseIRCURL: host/port split failed"); return null; } + // 1 = hostname or IPv4 address, 2 = port. specifiedHost = rv.host = ary[1].toLowerCase(); + rv.isserver = arrayHasElementAt(ary, 2) || /\.|:/.test(specifiedHost); if (arrayHasElementAt(ary, 2)) - { - rv.isserver = true; rv.port = parseInt(ary[2].substr(1)); - } - else - { - if (specifiedHost.indexOf(".") != -1) - rv.isserver = true; - } if (rest) { diff --git a/xul/content/static.js b/xul/content/static.js --- a/xul/content/static.js +++ b/xul/content/static.js @@ -1787,62 +1787,89 @@ } } -var testURLs = - ["irc:", "irc://", "irc:///", "irc:///help", "irc:///help,needkey", - "irc://irc.foo.org", "irc://foo:6666", - "irc://foo", "irc://irc.foo.org/", "irc://foo:6666/", "irc://foo/", - "irc://irc.foo.org/,needpass", "irc://foo/,isserver", - "irc://moznet/,isserver", "irc://moznet/", - "irc://foo/chatzilla", "irc://foo/chatzilla/", +var testURLs = [ + "irc:", + "irc://", + "irc://foo", + "irc://foo/", + "irc://foo/,isserver", + "irc://foo/chatzilla", + "irc://foo/chatzilla/", + "irc://foo:6666", + "irc://foo:6666/", + "irc://irc.foo.org", + "irc://irc.foo.org/", + "irc://irc.foo.org/,needpass", "irc://irc.foo.org/?msg=hello%20there", "irc://irc.foo.org/?msg=hello%20there&ignorethis", "irc://irc.foo.org/%23mozilla,needkey?msg=hello%20there&ignorethis", - "invalids", - "irc://irc.foo.org/,isnick"]; + "irc://moznet/", + "irc://moznet/,isserver", + "irc://[fe80::5d49:767b:4b68:1b17]", + "irc://[fe80::5d49:767b:4b68:1b17]/", + "irc://[fe80::5d49:767b:4b68:1b17]:6666", + "irc://[fe80::5d49:767b:4b68:1b17]:6666/" +]; + +var testFailURLs = [ + "irc:///", + "irc:///help", + "irc:///help,needkey", + "irc://irc.foo.org/,isnick", + "invalids" +]; function doURLTest() { - for (var u in testURLs) - { - dd("testing url \"" + testURLs[u] + "\""); - var o = parseIRCURL(testURLs[u]); + var passed = 0, total = testURLs.length + testFailURLs.length; + for (var i = 0; i < testURLs.length; i++) + { + var o = parseIRCURL(testURLs[i]); if (!o) - dd("PARSE FAILED!"); + display("Parse of '" + testURLs[i] + "' failed.", MT_ERROR); else - dd(dumpObjectTree(o)); - dd("---"); - } + passed++; + } + for (var i = 0; i < testFailURLs.length; i++) + { + var o = parseIRCURL(testFailURLs[i]); + if (o) + display("Parse of '" + testFailURLs[i] + "' unexpectedly succeeded.", MT_ERROR); + else + passed++; + } + display("Passed " + passed + " out of " + total + " tests (" + + passed / total * 100 + "%).", MT_INFO); } -var testIRCURLObjects = - [ - [{}, "irc://"], - [{host: "undernet"}, "irc://undernet/"], - [{host: "irc.undernet.org"}, "irc://irc.undernet.org/"], - [{host: "irc.undernet.org", isserver: true}, "irc://irc.undernet.org/"], - [{host: "undernet", isserver: true}, "irc://undernet/,isserver"], - [{host: "irc.undernet.org", port: 6667}, "irc://irc.undernet.org/"], - [{host: "irc.undernet.org", port: 1}, "irc://irc.undernet.org:1/"], - [{host: "irc.undernet.org", port: 1, scheme: "ircs"}, - "ircs://irc.undernet.org:1/"], - [{host: "irc.undernet.org", port: 9999, scheme: "ircs"}, - "ircs://irc.undernet.org/"], - [{host: "undernet", needpass: true}, "irc://undernet/,needpass"], - [{host: "undernet", pass: "cz"}, "irc://undernet/?pass=cz"], - [{host: "undernet", charset: "utf-8"}, "irc://undernet/?charset=utf-8"], - [{host: "undernet", target: "#foo"}, "irc://undernet/%23foo"], - [{host: "undernet", target: "#foo", needkey: true}, - "irc://undernet/%23foo,needkey"], - [{host: "undernet", target: "John", isnick: true}, - "irc://undernet/John,isnick"], - [{host: "undernet", target: "#foo", key: "cz"}, - "irc://undernet/%23foo?key=cz"], - [{host: "undernet", charset: "utf-8"}, "irc://undernet/?charset=utf-8"], - [{host: "undernet", target: "John", msg: "spam!"}, - "irc://undernet/John?msg=spam%21"], - [{host: "undernet", target: "foo", isnick: true, msg: "spam!", pass: "cz"}, - "irc://undernet/foo,isnick?msg=spam%21&pass=cz"] - ]; +var testIRCURLObjects = [ + [{}, "irc://"], + [{host: "undernet"}, "irc://undernet/"], + [{host: "irc.undernet.org"}, "irc://irc.undernet.org/"], + [{host: "irc.undernet.org", isserver: true}, "irc://irc.undernet.org/"], + [{host: "undernet", isserver: true}, "irc://undernet/,isserver"], + [{host: "irc.undernet.org", port: 6667}, "irc://irc.undernet.org/"], + [{host: "irc.undernet.org", port: 1}, "irc://irc.undernet.org:1/"], + [{host: "irc.undernet.org", port: 1, scheme: "ircs"}, + "ircs://irc.undernet.org:1/"], + [{host: "irc.undernet.org", port: 9999, scheme: "ircs"}, + "ircs://irc.undernet.org/"], + [{host: "undernet", needpass: true}, "irc://undernet/,needpass"], + [{host: "undernet", pass: "cz"}, "irc://undernet/?pass=cz"], + [{host: "undernet", charset: "utf-8"}, "irc://undernet/?charset=utf-8"], + [{host: "undernet", target: "#foo"}, "irc://undernet/%23foo"], + [{host: "undernet", target: "#foo", needkey: true}, + "irc://undernet/%23foo,needkey"], + [{host: "undernet", target: "John", isnick: true}, + "irc://undernet/John,isnick"], + [{host: "undernet", target: "#foo", key: "cz"}, + "irc://undernet/%23foo?key=cz"], + [{host: "undernet", charset: "utf-8"}, "irc://undernet/?charset=utf-8"], + [{host: "undernet", target: "John", msg: "spam!"}, + "irc://undernet/John?msg=spam%21"], + [{host: "undernet", target: "foo", isnick: true, msg: "spam!", pass: "cz"}, + "irc://undernet/foo,isnick?msg=spam%21&pass=cz"] +]; function doObjectURLtest() {