Skip to content
Myr

fix(utils/ipaddr): expand "::" to eight zero groups (#4973)

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

`expandIPv6('::')` returned 14 zero groups instead of 8. The unspecified address `::` splits into three empty sections (`['', '', '']`), but the loop only removed a single adjacent empty before expanding, so a second empty slot was expanded again and produced extra groups. Drain all consecutive empty sections before filling, leaving exactly one slot for the zero groups. Other forms keep working since a single `::` elsewhere yields at most two adjacent empties.

authored by youcef zr · committed by GitHub · parent 8e2cccc · Browse files · 2 files+8 added−1 removed
This commit

State

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

Trailers

  • Co-authored-by: youcefzemmar <dzbuildoff@gmail.com>
  • Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Diff stats

2 files+8 added−1 removed

  • tests:+4 added−0 removed
  • other:+4 added−1 removed

2 files+8 added−1 removed

modified:src/utils/ipaddr.test.ts+4 added
modified:src/utils/ipaddr.ts+4 added-1 removed
24 unmodified lines
25 const node = sections[i]26 if (node !== '') {27 sections[i] = node.padStart(4, '0')28 } else {29 // Keep a single empty slot for `::` zero expansion.30 while (sections[i + 1] === '') {29 sections[i + 1] === '' && sections.splice(i + 1, 1)31 sections.splice(i + 1, 1)32 }33 sections[i] = new Array(8 - sections.length + 1).fill('0000').join(':')34 }35 }36 return sections.join(':')
331 unmodified lines