diff --git a/classes/Leth/IPAddress/IP/NetworkAddress.php b/classes/Leth/IPAddress/IP/NetworkAddress.php index ea8f959..a85a466 100755 --- a/classes/Leth/IPAddress/IP/NetworkAddress.php +++ b/classes/Leth/IPAddress/IP/NetworkAddress.php @@ -187,7 +187,7 @@ abstract class NetworkAddress implements \IteratorAggregate, \Countable $last_added = $a; } } - if ($last_added !== $b && $last_added->compare_to($b) !== 0) + if (!$last_added || ($last_added !== $b && $last_added->compare_to($b) !== 0)) $out[] = $b; // We're done with these, remove them to allow GC unset($cidr_addrs[$cidr]); diff --git a/tests/IPNetworkAddressTest.php b/tests/IPNetworkAddressTest.php index 09df6dd..37cb984 100644 --- a/tests/IPNetworkAddressTest.php +++ b/tests/IPNetworkAddressTest.php @@ -491,6 +491,11 @@ class IP_NetworkAddress_Test extends PHPUnit_Framework_TestCase array('0.0.0.0/32', '0.0.0.1/32', '::0/128', '::1/128'), array('0.0.0.0/31', '::0/127'), ), + // Merge with duplicate resultant entry + array( + array('0.0.0.0/22', '0.0.0.0/24', '0.0.1.0/24', '0.0.2.0/24', '0.0.3.0/24'), + array('0.0.0.0/22'), + ), ); foreach ($data as &$x)