Skip to content
Myr

fix(utils/ipaddr): avoid truncation on embedded IPv4 addresses in expandIPv6 (#5247)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nanasi · committed by GitHub · parent eea9735 · Browse files · 2 files+8 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−4 removed

  • tests:+3 added−0 removed
  • other:+5 added−4 removed

2 files+8 added−4 removed

modified:src/utils/ipaddr.test.ts+3 added
modified:src/utils/ipaddr.ts+5 added-4 removed
10 unmodified lines
11 * @return expanded IPv6 Address12 */13export const expandIPv6 = (ipV6: string): string => {14 const sections = ipV6.split(':')15 if (IPV4_REGEX.test(sections.at(-1) as string)) {15 const lastSection = sections.at(-1) as string16 if (IPV4_REGEX.test(lastSection)) {17 const octets = lastSection.split('.').map(Number)18 sections.splice(19 -1,20 1,19 ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1) as string)) // => ::7f00:000120 .substring(2) // => 7f00:000121 .split(':') // => ['7f00', '0001']21 ((octets[0] << 8) | octets[1]).toString(16),22 ((octets[2] << 8) | octets[3]).toString(16)23 )24 }25 for (let i = 0; i < sections.length; i++) {26 const node = sections[i]
348 unmodified lines