From ffb96d7ad9becd7ef62bb80db1161bc00fbd83b1 Mon Sep 17 00:00:00 2001 From: Marcus Cobden <52370+leth@users.noreply.github.com> Date: Sat, 16 Mar 2024 21:34:06 +0000 Subject: [PATCH 1/2] Only compress 2 or more zeroed IPv6 Hextets Fixes #38 --- classes/Leth/IPAddress/IPv6/Address.php | 3 ++- tests/IPv6AddressTest.php | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/classes/Leth/IPAddress/IPv6/Address.php b/classes/Leth/IPAddress/IPv6/Address.php index 255c399..76520cd 100755 --- a/classes/Leth/IPAddress/IPv6/Address.php +++ b/classes/Leth/IPAddress/IPv6/Address.php @@ -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'); diff --git a/tests/IPv6AddressTest.php b/tests/IPv6AddressTest.php index b1f28ce..3f30941 100644 --- a/tests/IPv6AddressTest.php +++ b/tests/IPv6AddressTest.php @@ -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'), ); } From 9ebc90adbebc2d6b47e9176f029053ba2755dca9 Mon Sep 17 00:00:00 2001 From: Marcus Cobden <52370+leth@users.noreply.github.com> Date: Sat, 16 Mar 2024 21:55:26 +0000 Subject: [PATCH 2/2] Fix undeclared variables --- classes/Leth/IPAddress/IP/NetworkAddress.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/Leth/IPAddress/IP/NetworkAddress.php b/classes/Leth/IPAddress/IP/NetworkAddress.php index cfd3859..75efe0f 100755 --- a/classes/Leth/IPAddress/IP/NetworkAddress.php +++ b/classes/Leth/IPAddress/IP/NetworkAddress.php @@ -183,6 +183,7 @@ public static function merge(array $network_addresses): array usort($net_addrs, array(__CLASS__, 'compare')); $last_added = NULL; + $a = $b = NULL; for ($i = 0; $i < count($net_addrs) - 1; $i++) { $a = $net_addrs[$i]; $b = $net_addrs[$i + 1];