diff --git a/binding/javascript/tests/ip.test.js b/binding/javascript/tests/ip.test.js index 481b13c..2e78433 100644 --- a/binding/javascript/tests/ip.test.js +++ b/binding/javascript/tests/ip.test.js @@ -10,7 +10,7 @@ import * as util from '../util.js'; test('parse ip address', () => { let ip_list = [ "1.0.0.0", "58.251.30.115", "192.168.1.100", "126.255.32.255", "219.xx.xx.11", - "::", "::1", "fffe::", "2c0f:fff0::", "2c0f:fff0::1", + "::", "::1", "fffe::", "2c0f:fff0::", "2c0f:fff0::1", "2a02:26f7:c409:4001::", "2fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "240e:982:e617:ffff:ffff:ffff:ffff:ffff", "::xx:ffff" ]; @@ -26,6 +26,7 @@ test('parse ip address', () => { let to_Str = ipBytes == null ? '0' : util.ipToString(ipBytes, true); let toByte = ipBytes == null ? '0' : util.ipBytesString(ipBytes); console.log(`parseIP(${ipString}): {Bytes: ${toByte}, String: ${to_Str}}`); + expect(ipString).toBe(to_Str); }); }); diff --git a/binding/javascript/util.js b/binding/javascript/util.js index d388715..4fb7c1a 100644 --- a/binding/javascript/util.js +++ b/binding/javascript/util.js @@ -196,7 +196,7 @@ function _ipv6_to_string(v6Bytes, compress) { _.push(''); // empty for double colon // make sure there is an empty tail - if (i == ps.length && _.length == 2) { + if (i == ps.length && _.length < ps.length) { _.push(''); } } @@ -375,4 +375,7 @@ export function loadContentFromFile(dbPath) { const content = loadContent(fd); fs.close(fd, function(){}); return content; -} \ No newline at end of file +} + +const ipBytes = parseIP("2a02:26f7:c409:4001::"); +console.log(ipToString(ipBytes)); \ No newline at end of file