| 14 | // matching. 0.0.0.0 is covered by LOOPBACK_HOSTNAMES; this handles compressed |
| 15 | // and full IPv6 all-zero forms so both families bypass symmetrically. |
| 16 | const isIPv6Unspecified = (host) => { |
| 17 | if (host === '::') return true; |
| 18 | |
| 19 | const compressionIndex = host.indexOf('::'); |
| 20 | |
| 21 | if (compressionIndex !== -1) { |
| 22 | if (compressionIndex !== host.lastIndexOf('::')) return false; |
| 23 | |
| 24 | const left = host.slice(0, compressionIndex); |
| 25 | const right = host.slice(compressionIndex + 2); |
| 26 | const leftGroups = left ? left.split(':') : []; |
| 27 | const rightGroups = right ? right.split(':') : []; |
| 28 | const explicitGroups = leftGroups.length + rightGroups.length; |
| 29 | |
| 30 | return ( |
| 31 | explicitGroups < 8 && |
| 32 | leftGroups.every(isIPv6ZeroGroup) && |
| 33 | rightGroups.every(isIPv6ZeroGroup) |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | const groups = host.split(':'); |
| 38 | return groups.length === 8 && groups.every(isIPv6ZeroGroup); |
| 39 | }; |
| 40 | |
| 41 | const isIPv6Loopback = (host) => { |
| 42 | // Collapse all-zero groups: any form of ::1 / 0:0:...:0:1 |