Skip to content

Commit b9a9110

Browse files
committed
Do not call substr_count() if ip is null to avoid deprecation warning in PHP 8.1
1 parent 8688860 commit b9a9110

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

IpUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ private function __construct()
3737
*/
3838
public static function checkIp($requestIp, $ips)
3939
{
40+
if (null === $requestIp) {
41+
return false;
42+
}
43+
4044
if (!\is_array($ips)) {
4145
$ips = [$ips];
4246
}

Tests/IpUtilsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function getIpv4Data()
3939
[true, '1.2.3.4', '192.168.1.0/0'],
4040
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
4141
[false, 'an_invalid_ip', '192.168.1.0/24'],
42+
[false, '', '1.2.3.4/1'],
43+
[false, null, '1.2.3.4/1'],
4244
];
4345
}
4446

@@ -69,6 +71,8 @@ public function getIpv6Data()
6971
[false, '2a01:198:603:0:396e:4789:8e99:890f', ['::1', '1a01:198:603:0::/65']],
7072
[false, '}__test|O:21:"JDatabaseDriverMysqli":3:{s:2', '::1'],
7173
[false, '2a01:198:603:0:396e:4789:8e99:890f', 'unknown'],
74+
[false, '', '::1'],
75+
[false, null, '::1'],
7276
];
7377
}
7478

0 commit comments

Comments
 (0)