Skip to content

Commit

Permalink
minor #43357 [HttpFoundation] Fix PHP 8.1 deprecation notice in IpUti…
Browse files Browse the repository at this point in the history
…ls::checkIp() (W0rma)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] Fix PHP 8.1 deprecation notice in IpUtils::checkIp()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #43350
| License       | MIT
| Doc PR        |

After this PR got merged I will create additional PRs to deprecate (5.4)/remove (6.0) passing `null` to various methods in `IpUtils` like suggested in #43350 (comment)

Commits
-------

5e991db Do not call substr_count() if ip is null to avoid deprecation warning in PHP 8.1
  • Loading branch information
fabpot committed Oct 10, 2021
2 parents c798618 + 5e991db commit ab7884c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Expand Up @@ -37,6 +37,10 @@ private function __construct()
*/
public static function checkIp($requestIp, $ips)
{
if (null === $requestIp) {
return false;
}

if (!\is_array($ips)) {
$ips = [$ips];
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Expand Up @@ -39,6 +39,8 @@ public function getIpv4Data()
[true, '1.2.3.4', '192.168.1.0/0'],
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
[false, 'an_invalid_ip', '192.168.1.0/24'],
[false, '', '1.2.3.4/1'],
[false, null, '1.2.3.4/1'],
];
}

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

Expand Down

0 comments on commit ab7884c

Please sign in to comment.