Skip to content

Commit 48cbccf

Browse files
authored
Merge pull request #39 from leth/fix-ipv6-addr-compression
Only compress 2 or more zeroed IPv6 Hextets
2 parents 1c5acc5 + 9ebc90a commit 48cbccf

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

classes/Leth/IPAddress/IP/NetworkAddress.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public static function merge(array $network_addresses): array
183183
usort($net_addrs, array(__CLASS__, 'compare'));
184184

185185
$last_added = NULL;
186+
$a = $b = NULL;
186187
for ($i = 0; $i < count($net_addrs) - 1; $i++) {
187188
$a = $net_addrs[$i];
188189
$b = $net_addrs[$i + 1];

classes/Leth/IPAddress/IPv6/Address.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ public function format(int $mode): string
241241

242242
case IP\Address::FORMAT_COMPACT:
243243
$best_pos = $zeros_pos = FALSE;
244-
$best_count = $zeros_count = 0;
244+
$best_count = 1;
245+
$zeros_count = 0;
245246
foreach ($parts as $i => $quad)
246247
{
247248
$parts[$i] = ($quad === '0000') ? '0' : ltrim($quad, '0');

tests/IPv6AddressTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function providerFactory(): array
4747
'::ffff:127:0:0:1',
4848
'0:0:0:ffff:127:0:0:1',
4949
'0000:0000:0000:ffff:0127:0000:0000:0001'),
50+
array(
51+
'2001:504:0:1:0:3:1898:1',
52+
'2001:504:0:1:0:3:1898:1',
53+
'2001:504:0:1:0:3:1898:1',
54+
'2001:0504:0000:0001:0000:0003:1898:0001'),
5055
);
5156
}
5257

0 commit comments

Comments
 (0)