valibot: [v0.31.0-rc.5] The internal function `_stringify` has a problem
The internal function _stringify has a problem. It may happen that constructor is undefined, so when trying to access constructor.name an error is thrown because name cannot be accessed since constructor is `undefined.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (9 by maintainers)
Commits related to this issue
- Fix and improve _stringify util for special edge cases #608 — committed to fabian-hiller/valibot by fabian-hiller 2 years ago
- Change object check to make schemas more compatible and flexible #608 — committed to fabian-hiller/valibot by fabian-hiller 2 years ago
This is fixed in v0.31.0-rc.6
Due to our small bundle size, Zods solution does not work for us. 🫤
My reply https://github.com/fabian-hiller/valibot/issues/608#issuecomment-2135423650 - Yes, I agree. I think
input && typeof input === 'object'is the only check that cannot be manipulated by developers. It will always work as expected. But by doing so, specific object types will also get accepted (likeArray,Dateand so on), which is fine because technically specific objects still belong to the generalobjecttype. I would recommend usinginput && typeof input === 'object'as a temporary change until we can find a better solution.The first
?is useful in cases whereObject.getPrototypeOf(input)isnullbut there are also cases whereObject.getPrototypeOf(input)is an empty object{}so the first?has no effect, therefore trying to access thenameproperty of theconstructorwill throw error since theconstructorproperty does not exist on an empty object{}. For this reason, it is necessary to use two?.