Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

min/max/assert not applyed on default value #30

Open
ncou opened this issue Oct 23, 2020 · 2 comments
Open

min/max/assert not applyed on default value #30

ncou opened this issue Oct 23, 2020 · 2 comments

Comments

@ncou
Copy link

ncou commented Oct 23, 2020

Hi,

It seems the controles like min/max or assert() are not appplyed on the default value.
This could be problematic if the default value is dynamic.

In my use case i should controle the application key is a hexa 64 chars, and by default we use the environement variable APP_KEY.

I also tryed to move the min/max/assert function after the chained ->default(), but the result is the same :(

return Expect::structure([ 'key' => Expect::xdigit()->min(64)->max(64)->default(env('APP_KEY')), ]);

Is that a bug or an "expected" behaviour ?

Keep up the good work.

@dg
Copy link
Member

dg commented Dec 18, 2020

Sometimes the default value doesn't really follow the rules, for example Expect::string() has default value null, but it doesn't allow null. So it's more like expected behaviour.

@ncou
Copy link
Author

ncou commented Dec 18, 2020

Yes you are right, but it seems more logic to enforce the rules if the default value is explicitely defined. And have an error in the illogical cases like Expect::string()->default(123)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants