8000 Do not call substr_count() if ip is null to avoid deprecation warning… · symfony/symfony@870ea00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 870ea00

Browse files
committed
Do not call substr_count() if ip is null to avoid deprecation warning in PHP 8.1
1 parent 8d203a9 commit 870ea00

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public static function checkIp($requestIp, $ips)
4141
$ips = [$ips];
4242
}
4343

44+
if (null === $requestIp) {
45+
return false;
46+
}
47+
4448
$method = substr_count($requestIp, ':') > 1 ? 'checkIp6' : 'checkIp4';
4549

4650
foreach ($ips as $ip) {

src/Symfony/Component/HttpFoundation/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)
0