Skip to content

Commit

Permalink
Only compress 2 or more zeroed IPv6 Hextets
Browse files Browse the repository at this point in the history
  • Loading branch information
leth committed Mar 16, 2024
1 parent 1c5acc5 commit 0f99ae6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion classes/Leth/IPAddress/IPv6/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ public function format(int $mode): string

case IP\Address::FORMAT_COMPACT:
$best_pos = $zeros_pos = FALSE;
$best_count = $zeros_count = 0;
$best_count = 1;
$zeros_count = 0;
foreach ($parts as $i => $quad)
{
$parts[$i] = ($quad === '0000') ? '0' : ltrim($quad, '0');
Expand Down
5 changes: 5 additions & 0 deletions tests/IPv6AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function providerFactory(): array
'::ffff:127:0:0:1',
'0:0:0:ffff:127:0:0:1',
'0000:0000:0000:ffff:0127:0000:0000:0001'),
array(
'2001:504:0:1:0:3:1898:1',
'2001:504:0:1:0:3:1898:1',
'2001:504:0:1:0:3:1898:1',
'2001:0504:0000:0001:0000:0003:1898:0001'),
);
}

Expand Down

0 comments on commit 0f99ae6

Please sign in to comment.