WebbyLab / php-validator-livr

Lightweight PHP validator supporting Language Independent Validation Rules Specification (LIVR)
45 stars 16 forks source link

Fix bug with one_of rule #13

Closed antonfin closed 9 years ago

antonfin commented 9 years ago

You can see the problem hire - http://livr-playground.tk/#%7B%22rules%22%3A%22%7B%5Cn%20%20flag%3A%20%7Bone_of%3A%20%5Btrue%2C%20false%5D%7D%5Cn%7D%22%2C%22input%22%3A%22%7B%5Cn%20%20flag%3A%20'string%20or%20number'%5Cn%7D%22%7D

DanielHreben commented 9 years ago

It leads to another controversial behavior:

[ 
    'flag' => ['one_of' => [True, False]] // Converted to strings ['1', '0'], and in this case True == '1'
]

So if such strings will be passed for validation - we do not get an error. This case is really tricky and we don't have consistant behavior in all implementations yet: http://livr-playground.tk/#%7B%22rules%22%3A%22%7B%5Cn%20%20flag%3A%20%7Bone_of%3A%20%5Btrue%2C%20false%5D%7D%2C%5Cn%7D%22%2C%22input%22%3A%22%7B%5Cn%20%20flag%3A%20'1'%2C%5Cn%7D%22%7D

We must decide what is right: implicit type conversion (usually worse) or strict type checks (don't know how we can handle it in Perl implementation). @koorchik please take a look.