diff --git a/lib/internal/net.js b/lib/internal/net.js index 4a9a156aeabf66..2df1d5d5f613d2 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -25,7 +25,7 @@ const IPv6Reg = new RegExp('^(' + `(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` + `(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` + `(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` + -')(%[0-9a-zA-Z]{1,})?$'); +')(%[0-9a-zA-Z-.:]{1,})?$'); function isIPv4(s) { return IPv4Reg.test(s); diff --git a/test/parallel/test-net-isip.js b/test/parallel/test-net-isip.js index e9a8749aaee412..840ffe76af9a30 100644 --- a/test/parallel/test-net-isip.js +++ b/test/parallel/test-net-isip.js @@ -46,6 +46,9 @@ assert.strictEqual(net.isIP('::2001:252:1:2008:6'), 6); assert.strictEqual(net.isIP('::2001:252:1:1.1.1.1'), 6); assert.strictEqual(net.isIP('::2001:252:1:255.255.255.255'), 6); assert.strictEqual(net.isIP('::2001:252:1:255.255.255.255.76'), 0); +assert.strictEqual(net.isIP('fe80::2008%eth0'), 6); +assert.strictEqual(net.isIP('fe80::2008%eth0.0'), 6); +assert.strictEqual(net.isIP('fe80::2008%eth0@1'), 0); assert.strictEqual(net.isIP('::anything'), 0); assert.strictEqual(net.isIP('::1'), 6); assert.strictEqual(net.isIP('::'), 6);