Skip to content

Commit

Permalink
net: allow wider regex in interface name
Browse files Browse the repository at this point in the history
Zone IDs on Linux are network interface names. The regex we use to
determine valid IPs does not allow for non-alphanumeric characters
in the zone ID suffix. Some machines (including the RHEL Linux/s390x
machines from Marist) have zone IDs with a '.' character in them
which the regex in net.isIP rejects. This changes the regex.

Ref: #14500

Signed-off-by: Stewart Addison <sxa@uk.ibm.com>
  • Loading branch information
Stewart Addison committed Jul 14, 2020
1 parent 63a856f commit 1748917
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/net.js
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-net-isip.js
Expand Up @@ -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);
Expand Down

0 comments on commit 1748917

Please sign in to comment.