From 09a70985fbfc016c71617d15f5cf826c7a75714e Mon Sep 17 00:00:00 2001 From: Mykhailo Gorianskyi Date: Wed, 9 Oct 2024 22:11:05 +0200 Subject: [PATCH] Fixed an issue when some ip v6 weren't found --- package.json | 2 +- src/index.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 62b23c7c..78612e05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "ip-index", - "version": "2.0.17", + "version": "2.1.0", "repository": "https://github.com/Umkus/ip-index.git", "license": "UNLICENCED", "description": "Block-list containing IPs belonging to hosting data centers", diff --git a/src/index.js b/src/index.js index 79bcea4a..083a8310 100644 --- a/src/index.js +++ b/src/index.js @@ -34,13 +34,17 @@ function getPosition(subnet, start) { const part = subnet.split(/[:\.]/)[start] const isIpV6 = subnet.includes(':') + if (!part) { + return null + } + return parseInt(part, isIpV6 ? 16 : 10) } // Check if ip 4 vs 6 function indexRow(item, index, indexes) { - if (!index || !item) { + if (!item) { return null } @@ -127,7 +131,7 @@ export function getIpInfo(ip) { ipPosition2 = availableKeys.reverse().find((key) => key <= ipPosition2) if (!indexes[ipPosition1][ipPosition2]) { - return [] + return indexes[ipPosition1][null] || [] } }