Closed Yousha closed 5 months ago
The original output is equivalent to the negated result of using FILTER_FLAG_NO_PRIV_RANGE only: php will treat null and invalid strings as private, so the "is it an ip?"-check indeed must be done separately.
As the other methods are affected as well, I'd suggest to add an isIP-method in order to combine it with the additional flags.
Fix incorrect usage of the
FILTER_FLAG_NO_PRIV_RANGE
flag in thefilter_var()
function.The
FILTER_FLAG_NO_PRIV_RANGE
flag is used to EXCLUDE private IP ranges. But in the code, the flag is used with theFILTER_VALIDATE_IP
filter, which actually VALIDATES the IP address. As a result, the method returns the opposite result of what is intended. So we need to change the usage of theFILTER_FLAG_NO_PRIV_RANGE
flag. Instead of using it with theFILTER_VALIDATE_IP
filter, we should use it with theFILTER_FLAG_NO_PRIV_RANGE
flag DIRECTLY.By using old(bugged) function we have:
Now by using new(fixed) function we have: