diff --git a/Changelog.txt b/Changelog.txt index c6c04db..ae4c72b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -9,6 +9,16 @@ Versioning guidelines for SemVer can be found at: https://semver.org/ (none) +=== Version/Release 1.3.3 === +PATCH RELEASE. + +- [2021.10.23; Bug-fix; Maikuolan]: Aggregating a single IP address with its + own CIDR equivalent (i.e., a range containing just one IP address) produced + output with a wider than expected range; Fixed. + +Caleb M (Maikuolan), +October 23, 2021. + === Version/Release 1.3.2 === MAINTENANCE RELEASE. diff --git a/src/Aggregator.php b/src/Aggregator.php index 10b660b..bb77e4d 100644 --- a/src/Aggregator.php +++ b/src/Aggregator.php @@ -509,7 +509,9 @@ private function mergeRanges(&$In) if (!$CIDRs = $this->ExpandIPv4($CIDR, false, $Size - 1)) { $CIDRs = $this->ExpandIPv6($CIDR, false, $Size - 1); } - if ( + if ($Line === $PrevLine) { + $Out = str_replace("\n" . $PrevLine . "\n" . $Line . "\n", "\n" . $Line . "\n", $Out); + } elseif ( !empty($CIDRs[$Size - 1]) && !empty($PrevCIDRs[$PrevSize - 1]) && !empty($CIDRs[$Size - 2]) && diff --git a/tests.php b/tests.php index 2832b59..0f61bd1 100644 --- a/tests.php +++ b/tests.php @@ -140,5 +140,19 @@ } } +$TestInput = '1.0.0.0/32 +1.0.0.0'; + +$ExpectedOutput = '1.0.0.0/32'; + +$Aggregator = new \CIDRAM\Aggregator\Aggregator(); +$Aggregator->Results = true; +$Aggregated = $Aggregator->aggregate($TestInput); + +if ($ExpectedOutput !== $Aggregated) { + echo 'Output is bugged.' . PHP_EOL; + exit(5); +} + echo 'All tests passed.' . PHP_EOL; exit(0);