[php-src] Issue #11098: filter_var FILTER_VALIDATE_IP with ip '0.2.3.4' will return true
| From: | joe820912boy | Date: | Tue, 18 Apr 2023 04:04:26 +0000 |
| Subject: | [php-src] Issue #11098: filter_var FILTER_VALIDATE_IP with ip '0.2.3.4' will return true | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244222@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11098
Author: joe820912boy
### Description
The following code:
```php
<?php
$ip = '0.2.3.4'; // replace with the IP address you want to validate
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
echo "$ip is a valid IP address";
} else {
echo "$ip is not a valid IP address";
}
```
Resulted in this output:
```
0.2.3.4 is a valid IP address
```
But I expected this output instead:
```
not a valid IP address
```
I check this code on https://onlinephp.io/c/b1510
I think that '0.2.3.4' shouldn't be a valid ip address with 0 in the head.
But the filter_var will return true for this error ip
### PHP Version
8.2.5
### Operating System
_No response_