From 0fe9fca88f5a14a33822c90968c6912ba2b64bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Wed, 21 Feb 2024 18:19:10 +0100 Subject: [PATCH 1/2] Add test for loopback ip with uppercase ::FFFF: --- test/api-test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/api-test.js b/test/api-test.js index 0db838d..396dcea 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -413,6 +413,12 @@ describe('IP library for node.js', () => { assert.ok(ip.isLoopback('::')); }); }); + + describe('::FFFF:127.0.0.1', () => { + it('should respond with true', () => { + assert.ok(ip.isLoopback('::FFFF:127.0.0.1')); + }); + }); }); describe('address() method', () => { From 1a2fb61f46e319240c4ff31f7b3d1432f47ceb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Wed, 21 Feb 2024 18:19:56 +0100 Subject: [PATCH 2/2] Fix isLoopback with uppercase ::FFFF: --- lib/ip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ip.js b/lib/ip.js index 9022443..e7f0920 100644 --- a/lib/ip.js +++ b/lib/ip.js @@ -343,7 +343,7 @@ ip.isLoopback = function (addr) { addr = ip.fromLong(Number(addr)); } - return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/ + return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/i .test(addr) || /^0177\./.test(addr) || /^0x7f\./i.test(addr)