Skip to content

Commit be8401b

Browse files
committed
feature #43550 [HttpFoundation] Remove possibility to pass null as $requestIp in IpUtils (W0rma)
This PR was merged into the 6.0 branch. Discussion ---------- [HttpFoundation] Remove possibility to pass null as $requestIp in IpUtils | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #43350 (comment) | License | MIT | Doc PR | Removes the code which was deprecated in #43411 Commits ------- e95e97d Remove possibility to pass null as $requestIp in IpUtils
2 parents 4e69ecd + e95e97d commit be8401b

File tree

4 files changed

+5
-48
lines changed

4 files changed

+5
-48
lines changed

UPGRADE-6.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ HttpFoundation
123123
* Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array)
124124
* Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException`
125125
* Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException`
126+
* Passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()` is not supported anymore.
126127

127128
HttpKernel
128129
----------

src/Symfony/Component/HttpFoundation/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHANGELOG
1717
* Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array)
1818
* Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException`
1919
* Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException`
20+
* Passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()` is not supported anymore.
2021

2122
5.4
2223
---

src/Symfony/Component/HttpFoundation/IpUtils.php

+3-21
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ private function __construct()
3232
*
3333
* @param string|array $ips List of IPs or subnets (can be a string if only a single one)
3434
*/
35-
public static function checkIp(?string $requestIp, string|array $ips): bool
35+
public static function checkIp(string $requestIp, string|array $ips): bool
3636
{
37-
if (null === $requestIp) {
38-
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);
39-
40-
return false;
41-
}
42-
4337
if (!\is_array($ips)) {
4438
$ips = [$ips];
4539
}
@@ -63,14 +57,8 @@ public static function checkIp(?string $requestIp, string|array $ips): bool
6357
*
6458
* @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
6559
*/
66-
public static function checkIp4(?string $requestIp, string $ip): bool
60+
public static function checkIp4(string $requestIp, string $ip): bool
6761
{
68-
if (null === $requestIp) {
69-
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);
70-
71-
return false;
72-
}
73-
7462
$cacheKey = $requestIp.'-'.$ip;
7563
if (isset(self::$checkedIps[$cacheKey])) {
7664
return self::$checkedIps[$cacheKey];
@@ -114,14 +102,8 @@ public static function checkIp4(?string $requestIp, string $ip): bool
114102
*
115103
* @throws \RuntimeException When IPV6 support is not enabled
116104
*/
117-
public static function checkIp6(?string $requestIp, string $ip): bool
105+
public static function checkIp6(string $requestIp, string $ip): bool
118106
{
119-
if (null === $requestIp) {
120-
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);
121-
122-
return false;
123-
}
124-
125107
$cacheKey = $requestIp.'-'.$ip;
126108
if (isset(self::$checkedIps[$cacheKey])) {
127109
return self::$checkedIps[$cacheKey];

src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

-27
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,6 @@ public function getIpv6Data()
7777
];
7878
}
7979

80-
/**
81-
* @group legacy
82-
*/
83-
public function testIpTriggersDeprecationOnNull()
84-
{
85-
$this->expectDeprecation('Since symfony/http-foundation 5.4: Passing null as $requestIp to "Symfony\Component\HttpFoundation\IpUtils::checkIp()" is deprecated, pass an empty string instead.');
86-
$this->assertFalse(IpUtils::checkIp(null, '192.168.1.1'));
87-
}
88-
89-
/**
90-
* @group legacy
91-
*/
92-
public function testIp4TriggersDeprecationOnNull()
93-
{
94-
$this->expectDeprecation('Since symfony/http-foundation 5.4: Passing null as $requestIp to "Symfony\Component\HttpFoundation\IpUtils::checkIp4()" is deprecated, pass an empty string instead.');
95-
$this->assertFalse(IpUtils::checkIp4(null, '192.168.1.1'));
96-
}
97-
98-
/**
99-
* @group legacy
100-
*/
101-
public function testIp6TriggersDeprecationOnNull()
102-
{
103-
$this->expectDeprecation('Since symfony/http-foundation 5.4: Passing null as $requestIp to "Symfony\Component\HttpFoundation\IpUtils::checkIp6()" is deprecated, pass an empty string instead.');
104-
$this->assertFalse(IpUtils::checkIp6(null, '2a01:198:603:0::/65'));
105-
}
106-
10780
/**
10881
* @requires extension sockets
10982
*/

0 commit comments

Comments
 (0)