nette / schema

📐 Validating data structures against a given Schema.
https://doc.nette.org/schema
Other
886 stars 26 forks source link

String expectation with min(0) and a nullable flag does not accept null #23

Closed finwe closed 3 years ago

finwe commented 4 years ago

Version: 1.0.2

Bug Description

String expectation with min(0) and a nullable flag does not accept null.

Steps To Reproduce

Expectation is defined as

$schema = Expect::structure([
    'position' => Expect::string()->min(0)->nullable(),
]);

When validating with ['position' => null], the error message raised is

"The option 'position' expects to be string or null in range 0.., null given."

Expected Behavior

The null value should be accepted according to the error message.

If failing for other reasons, null should be mentioned first in the error message for it to make more sense (only strings have "ranges")

Possible Solution

Nullable does not take precedence over string length constraint even when minimal string length is 0

finwe commented 4 years ago

Solution is to omit the ->min(0), yet the current behaviour is confusing anyway.