Closed vladshcherbin closed 3 months ago
Cause: Last check from object doesn't pass.
I made the check stricter to only match plain objects. I don't know why process.env
is not a plain object. Object.getPrototypeOf(process.env).constructor.name
returns an empty string. Not sure if we should make the check less strict because of this.
{ ...process.env }
works because it returns a plain object with all the properties of process.env
.
I also have no idea and it'll be strange if it doesn't pass.
Out of interest quick test:
zod
- passIf others encounter the same problem, I would like to hear their opinions and whether the workaround is sufficient.
From #602. Happy to hear your feedback.
There are other problems with the current plain object check, for example in #587, but I am not sure if Valibot is the problem. Normally, this should not be a problem. We could remove the
input.constructor === Object
check to make it less strict, but then any object that is notnull
will be accepted. In practice, this is usually not a problem because we never return the original object. So, strictly speaking, the validation is still safe. Therefore, I might make the validation less strict so as not to have to deal with special JS runtime behavior that we can't control.One problematic case that just came to my mind that could lead to unexpected behavior is our
looseObject
andobjectWithRest
schemas, as they can add unexpected data to the output if the wrong object types are passed.
This is fixed in v0.31.0-rc.6
Perfect, thank you!
I think the fix is good until a valid non-false object assumption is found 👍
Code:
Result:
looseObject
andstrictObject
valibot - 0.31.0-rc.0 node - 20.10.0