From e95e97d6fc301964eda624a374c89456d6059327 Mon Sep 17 00:00:00 2001 From: W0rma Date: Sun, 17 Oct 2021 19:36:14 +0200 Subject: [PATCH] Remove possibility to pass null as $requestIp in IpUtils --- UPGRADE-6.0.md | 1 + .../Component/HttpFoundation/CHANGELOG.md | 1 + .../Component/HttpFoundation/IpUtils.php | 24 +++-------------- .../HttpFoundation/Tests/IpUtilsTest.php | 27 ------------------- 4 files changed, 5 insertions(+), 48 deletions(-) diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 95a570186d741..6f1646e67263a 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -123,6 +123,7 @@ HttpFoundation * Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array) * Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException` * Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException` + * Passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()` is not supported anymore. HttpKernel ---------- diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index ea4cd7c9ef3f3..7ac49d12d7907 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -17,6 +17,7 @@ CHANGELOG * Retrieving non-scalar values using `InputBag::get()` will throw `BadRequestException` (use `InputBad::all()` instead to retrieve an array) * Passing non-scalar default value as the second argument `InputBag::get()` will throw `\InvalidArgumentException` * Passing non-scalar, non-array value as the second argument `InputBag::set()` will throw `\InvalidArgumentException` + * Passing `null` as `$requestIp` to `IpUtils::__checkIp()`, `IpUtils::__checkIp4()` or `IpUtils::__checkIp6()` is not supported anymore. 5.4 --- diff --git a/src/Symfony/Component/HttpFoundation/IpUtils.php b/src/Symfony/Component/HttpFoundation/IpUtils.php index ba357fb444b70..917ae31447d4e 100644 --- a/src/Symfony/Component/HttpFoundation/IpUtils.php +++ b/src/Symfony/Component/HttpFoundation/IpUtils.php @@ -32,14 +32,8 @@ private function __construct() * * @param string|array $ips List of IPs or subnets (can be a string if only a single one) */ - public static function checkIp(?string $requestIp, string|array $ips): bool + public static function checkIp(string $requestIp, string|array $ips): bool { - if (null === $requestIp) { - trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__); - - return false; - } - if (!\is_array($ips)) { $ips = [$ips]; } @@ -63,14 +57,8 @@ public static function checkIp(?string $requestIp, string|array $ips): bool * * @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet */ - public static function checkIp4(?string $requestIp, string $ip): bool + public static function checkIp4(string $requestIp, string $ip): bool { - if (null === $requestIp) { - trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__); - - return false; - } - $cacheKey = $requestIp.'-'.$ip; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; @@ -114,14 +102,8 @@ public static function checkIp4(?string $requestIp, string $ip): bool * * @throws \RuntimeException When IPV6 support is not enabled */ - public static function checkIp6(?string $requestIp, string $ip): bool + public static function checkIp6(string $requestIp, string $ip): bool { - if (null === $requestIp) { - trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__); - - return false; - } - $cacheKey = $requestIp.'-'.$ip; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; diff --git a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php index 018bb9f6b6c9f..5476c3d3018d5 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php @@ -77,33 +77,6 @@ public function getIpv6Data() ]; } - /** - * @group legacy - */ - public function testIpTriggersDeprecationOnNull() - { - $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.'); - $this->assertFalse(IpUtils::checkIp(null, '192.168.1.1')); - } - - /** - * @group legacy - */ - public function testIp4TriggersDeprecationOnNull() - { - $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.'); - $this->assertFalse(IpUtils::checkIp4(null, '192.168.1.1')); - } - - /** - * @group legacy - */ - public function testIp6TriggersDeprecationOnNull() - { - $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.'); - $this->assertFalse(IpUtils::checkIp6(null, '2a01:198:603:0::/65')); - } - /** * @requires extension sockets */