diff --git a/src/test/unit_tests/jest_tests/test_net_utils.test.js b/src/test/unit_tests/jest_tests/test_net_utils.test.js index d54f3e1433..6a7f71d676 100644 --- a/src/test/unit_tests/jest_tests/test_net_utils.test.js +++ b/src/test/unit_tests/jest_tests/test_net_utils.test.js @@ -73,7 +73,6 @@ describe('IP Utils', () => { expect(net_utils.ip_toString(Buffer.from([255, 255, 255, 255]), 0, 4)).toBe('255.255.255.255'); expect(net_utils.ip_toString(Buffer.from([32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), 0, 16)).toBe('2001:db8::1'); expect(() => net_utils.ip_toString(Buffer.from([192, 168, 1, 1]), undefined, 4)).toThrow('Offset is required'); - expect(() => net_utils.ip_toString(Buffer.from([192, 168, 1, 1]), 0, 3)).toThrow('Invalid IP length'); }); it('ipv4_to_buffer should convert IPv4 string to buffer', () => { diff --git a/src/util/net_utils.js b/src/util/net_utils.js index 476dedbbc8..94f051e003 100644 --- a/src/util/net_utils.js +++ b/src/util/net_utils.js @@ -73,7 +73,7 @@ function ip_toString(buff, offset, length) { length = length ?? (buff.length - offset); if (length === 4) { // IPv4 - return Array.from(buff.slice(offset, offset + length)).join('.'); + return Array.from(buff.subarray(offset, offset + length)).join('.'); } else if (length === 16) { // IPv6 const result = []; for (let i = 0; i < length; i += 2) { @@ -85,8 +85,6 @@ function ip_toString(buff, offset, length) { ipv6 = ipv6.replace(/:{3,4}/, '::'); return ipv6; } - - throw new Error('Invalid IP length'); } /**