Respect / Validation

The most awesome validation engine ever created for PHP
https://respect-validation.readthedocs.io
MIT License
5.76k stars 774 forks source link

filterVal not correct working with FILTER_VALIDATE_INT #1387

Closed nchizhov closed 1 year ago

nchizhov commented 2 years ago

If using filterVal with FILTER_VALIDATE_INT and validate (0, '0') its returns false, but should returns true;

Example:

$data = '0';
var_dump(var_dump(v::filterVar(FILTER_VALIDATE_INT)->validate($data));

returns false

But if will try to use php's filterVal:

$data = '0';
var_dump(filter_var($data, FILTER_VALIDATE_INT) !== false);

returns correct true.

alganet commented 1 year ago

You are absolutely right. Thanks for reporting 🐼 Sorry about the 6-month delay for the response, we were lacking time to dedicate to the project.

The filter_var function is more of a sanitizer, but we as a validation library do not care for that use case.

This issue was being caused because the FilterVar validator reuses the Callback validator in an envelope, and Callback casts the result to boolean. It caused this weird scenario in which the int 0 would be treated as false.

I've made the fix targeting release 2.3.

I'll be closing this once there is a release candidate.