summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Security/Normalizer/IpAddress.php3
-rw-r--r--tests/lib/Security/Normalizer/IpAddressTest.php4
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/private/Security/Normalizer/IpAddress.php b/lib/private/Security/Normalizer/IpAddress.php
index 84c87054c76..4edf83eca5e 100644
--- a/lib/private/Security/Normalizer/IpAddress.php
+++ b/lib/private/Security/Normalizer/IpAddress.php
@@ -68,6 +68,9 @@ class IpAddress {
* @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;
diff --git a/tests/lib/Security/Normalizer/IpAddressTest.php b/tests/lib/Security/Normalizer/IpAddressTest.php
index 36a48f601d3..97a8737ea9e 100644
--- a/tests/lib/Security/Normalizer/IpAddressTest.php
+++ b/tests/lib/Security/Normalizer/IpAddressTest.php
@@ -40,6 +40,10 @@ class IpAddressTest extends TestCase {
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'2001:db8:85a3::8a2e:370:7334/128',
],
+ [
+ '[::1]',
+ '::1/128',
+ ],
];
}