Skip to content

Commit

Permalink
fix parsing of some IPv4-embedded IPv6 adresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann150 committed Jan 23, 2024
1 parent babe357 commit 923dcdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ipaddr.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,11 @@
}
if ((match = string.match(ipv6Regexes.transitional))) {
zoneId = match[6] || '';
addr = expandIPv6(match[1].slice(0, -1) + zoneId, 6);
addr = match[1]
if (!match[1].endsWith('::')) {
addr = addr.slice(0, -1)
}
addr = expandIPv6(addr + zoneId, 6);
if (addr.parts) {
octets = [
parseInt(match[2]),
Expand Down
2 changes: 2 additions & 0 deletions test/ipaddr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ describe('ipaddr', () => {
assert.deepEqual(ipaddr.IPv6.parse('2001:db8:F53A::').parts, [0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 0]);
assert.deepEqual(ipaddr.IPv6.parse('::1').parts, [0, 0, 0, 0, 0, 0, 0, 1]);
assert.deepEqual(ipaddr.IPv6.parse('::8.8.8.8').parts, [0, 0, 0, 0, 0, 0xffff, 2056, 2056]);
assert.deepEqual(ipaddr.IPv6.parse('FFFF::255.255.255.255').parts, [0xffff, 0, 0, 0, 0, 0, 0xffff, 0xffff]);
assert.deepEqual(ipaddr.IPv6.parse('64:ff9a::0.0.0.0').parts, [0x64, 0xff9a, 0, 0, 0, 0, 0, 0]);
assert.deepEqual(ipaddr.IPv6.parse('::').parts, [0, 0, 0, 0, 0, 0, 0, 0]);
assert.deepEqual(ipaddr.IPv6.parse('::%z').parts, [0, 0, 0, 0, 0, 0, 0, 0]);
assert.deepEqual(ipaddr.IPv6.parse('::%z').zoneId, 'z');
Expand Down

0 comments on commit 923dcdd

Please sign in to comment.