Skip to content

Commit 0f67d43

Browse files
committed
net: fix IPv4 validation regex
Fixed the IPv4's validation regex so it also matches IPv4 octets that are prefixed by a `0` as they're also considered valid octets. Fixes: nodejs#40173
1 parent f367af4 commit 0f67d43

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/internal/net.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const { writeBuffer } = internalBinding('fs');
1111
const errors = require('internal/errors');
1212

1313
// IPv4 Segment
14-
const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
15-
const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
14+
const v4Seg = '(?:[0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
15+
const v4Str = `(?:${v4Seg}\\.){3}${v4Seg}`;
1616
const IPv4Reg = new RegExp(`^${v4Str}$`);
1717

1818
// IPv6 Segment

0 commit comments

Comments
 (0)