diff --git a/electron/puttyCommandLine.cjs b/electron/puttyCommandLine.cjs index c76e344b9..e2769ad3a 100644 --- a/electron/puttyCommandLine.cjs +++ b/electron/puttyCommandLine.cjs @@ -1,3 +1,5 @@ +const net = require("net"); + const SSH_PROTOCOL = "ssh"; const TELNET_PROTOCOL = "telnet"; @@ -145,10 +147,7 @@ function isDisplayIpv4(value) { } function isDisplayIpv6(value) { - if (!looksLikeIpv6(value)) return false; - if (!/^[0-9a-f:]+$/i.test(value)) return false; - const compressed = value.match(/::/g); - return !compressed || compressed.length === 1; + return net.isIP(value) === 6; } // A leftover IP positional is the PuTTY analogue of SecureCRT /N: the TCP diff --git a/electron/puttyCommandLine.test.cjs b/electron/puttyCommandLine.test.cjs index b19f80d73..c49bc88ee 100644 --- a/electron/puttyCommandLine.test.cjs +++ b/electron/puttyCommandLine.test.cjs @@ -428,6 +428,40 @@ test("parsePuttyCommandLine does not guess a tab name from several leftover addr assert.equal(parsed?.tabName, undefined); }); +test("parsePuttyCommandLine names IPv4-mapped and zone-scoped IPv6 jump targets", () => { + const mapped = parsePuttyCommandLine([ + "Netcatty.exe", + "-ssh", + "alice@[::ffff:192.0.2.10]@198.51.100.20", + "-pw", + "example", + ]); + assert.equal(mapped?.hostname, "198.51.100.20"); + assert.equal(mapped?.tabName, "::ffff:192.0.2.10"); + + const zoned = parsePuttyCommandLine([ + "Netcatty.exe", + "-ssh", + "alice@[fe80::1%eth0]@198.51.100.20", + "-pw", + "example", + ]); + assert.equal(zoned?.hostname, "198.51.100.20"); + assert.equal(zoned?.tabName, "fe80::1%eth0"); +}); + +test("parsePuttyCommandLine does not title a jump tab with a malformed colon string", () => { + const parsed = parsePuttyCommandLine([ + "Netcatty.exe", + "-ssh", + "alice@a:b:c@198.51.100.20", + "-pw", + "example", + ]); + assert.equal(parsed?.hostname, "198.51.100.20"); + assert.equal(parsed?.tabName, undefined); +}); + test("parsePuttyCommandLine uses a bracketed IPv6 target inside a jump login", () => { const parsed = parsePuttyCommandLine([ "Netcatty.exe",