From 0f67d43858adb4cfb9b6c9dfd023e86260da3d9f Mon Sep 17 00:00:00 2001 From: Voltrex Date: Wed, 22 Sep 2021 01:13:18 +0330 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/40173 --- lib/internal/net.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/net.js b/lib/internal/net.js index 8ae3170228dc..54194ce163fc 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -11,8 +11,8 @@ const { writeBuffer } = internalBinding('fs'); const errors = require('internal/errors'); // IPv4 Segment -const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; -const v4Str = `(${v4Seg}[.]){3}${v4Seg}`; +const v4Seg = '(?:[0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; +const v4Str = `(?:${v4Seg}\\.){3}${v4Seg}`; const IPv4Reg = new RegExp(`^${v4Str}$`); // IPv6 Segment