Skip to content
Snippets Groups Projects
Unverified Commit c9b58877 authored by Thomas Citharel's avatar Thomas Citharel
Browse files

Allow bracket IPv6 address format inside IPAdress Normalizer


When run with php's build-in server (for instance on localhost:8080), IP provided through $this->server['REMOTE_ADDR'] is [::1], which is not an acceptable format for \inet_pton. This removes the brackets if there's any.

Signed-off-by: default avatarThomas Citharel <tcit@tcit.fr>
parent 4d8f2c24
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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',
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment