Skip to content

Commit

Permalink
Bug-fix.
Browse files Browse the repository at this point in the history
Changelog excerpt:
- 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.
  • Loading branch information
Maikuolan committed Oct 23, 2021
1 parent 534e446 commit f50c76e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion src/Aggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) &&
Expand Down
14 changes: 14 additions & 0 deletions tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit f50c76e

Please sign in to comment.