Skip to content

Commit

Permalink
Merge pull request #13327 from nextcloud/allow-bracket-notation-for-r…
Browse files Browse the repository at this point in the history
…emove-ipv6-address

Allow bracket IPv6 address format inside IPAdress Normalizer
  • Loading branch information
MorrisJobke authored Mar 6, 2019
2 parents 58f6a77 + c9b5887 commit d004164
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/private/Security/Normalizer/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private function getIPv4Subnet(string $ip, int $maskBits = 32): string {
* @return string
*/
private function getIPv6Subnet(string $ip, int $maskBits = 48): string {
if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1]
$ip = substr($ip, 1, strlen($ip) - 2);
}
$binary = \inet_pton($ip);
for ($i = 128; $i > $maskBits; $i -= 8) {
$j = \intdiv($i, 8) - 1;
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/Security/Normalizer/IpAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function subnetDataProvider() {
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'2001:db8:85a3::8a2e:370:7334/128',
],
[
'[::1]',
'::1/128',
],
];
}

Expand Down

0 comments on commit d004164

Please sign in to comment.