Skip to content

Commit 254336e

Browse files
Merge branch '5.4' into 6.0
* 5.4: [HttpClient] fix RetryableHttpClient when a response is canceled Deprecate passing null as $requestIp to IpUtils::checkIp(), checkIp4() and checkIp6() [Uid] fix 4 missing bits of entropy in UUIDv4 Add a warning in WDT if using symfony/symfony [Notifier][Twilio] Ensure from/sender is valid via regex Lower log level in case of retry GuardEvent::getTransition() cannot return null [String] Add `trimSuffix()` and `trimPrefix()` methods [DependencyInjection] autowire union and intersection types [Runtime] Drop class validation of composer "extra.runtime.class"
2 parents d169373 + 96b7965 commit 254336e

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CHANGELOG
2121
5.4
2222
---
2323

24+
* Deprecate passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()`, pass an empty string instead.
2425
* Add the `litespeed_finish_request` method to work with Litespeed
2526
* Deprecate `upload_progress.*` and `url_rewriter.tags` session options
2627

IpUtils.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ private function __construct()
3535
public static function checkIp(?string $requestIp, string|array $ips): bool
3636
{
3737
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+
3840
return false;
3941
}
4042

@@ -63,6 +65,12 @@ public static function checkIp(?string $requestIp, string|array $ips): bool
6365
*/
6466
public static function checkIp4(?string $requestIp, string $ip): bool
6567
{
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+
6674
$cacheKey = $requestIp.'-'.$ip;
6775
if (isset(self::$checkedIps[$cacheKey])) {
6876
return self::$checkedIps[$cacheKey];
@@ -108,6 +116,12 @@ public static function checkIp4(?string $requestIp, string $ip): bool
108116
*/
109117
public static function checkIp6(?string $requestIp, string $ip): bool
110118
{
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+
111125
$cacheKey = $requestIp.'-'.$ip;
112126
if (isset(self::$checkedIps[$cacheKey])) {
113127
return self::$checkedIps[$cacheKey];

RequestMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function matches(Request $request): bool
174174
return false;
175175
}
176176

177-
if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
177+
if (IpUtils::checkIp($request->getClientIp() ?? '', $this->ips)) {
178178
return true;
179179
}
180180

Tests/IpUtilsTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\HttpFoundation\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\HttpFoundation\IpUtils;
1617

1718
class IpUtilsTest extends TestCase
1819
{
20+
use ExpectDeprecationTrait;
21+
1922
/**
2023
* @dataProvider getIpv4Data
2124
*/
@@ -40,7 +43,6 @@ public function getIpv4Data()
4043
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
4144
[false, 'an_invalid_ip', '192.168.1.0/24'],
4245
[false, '', '1.2.3.4/1'],
43-
[false, null, '1.2.3.4/1'],
4446
];
4547
}
4648

@@ -72,10 +74,36 @@ public function getIpv6Data()
7274
[false, '}__test|O:21:"JDatabaseDriverMysqli":3:{s:2', '::1'],
7375
[false, '2a01:198:603:0:396e:4789:8e99:890f', 'unknown'],
7476
[false, '', '::1'],
75-
[false, null, '::1'],
7677
];
7778
}
7879

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+
79107
/**
80108
* @requires extension sockets
81109
*/

0 commit comments

Comments
 (0)