jquense / yup

Dead simple Object schema validation
MIT License
22.94k stars 935 forks source link

tuple: index is string in ValidationError.inner.path when an array element is undefined or null #2148

Open alexdee2007 opened 11 months ago

alexdee2007 commented 11 months ago

https://github.com/jquense/yup/blob/5db2b2fdd6276ff8ae8c15e8aa9d3aa9710ad4ac/src/schema.ts#L549

Hi! Thanks for the wonderful library. I was sorting out some collisions in my application and noticed this. This implementation leads to the fact that when validating a tuple array, if the element of the array is not defined or is null, the index of the array in the path becomes a string, for example TupleArray["1"] instead of TupleArray[1].

stormitornado commented 11 months ago

Hi, I've also faced this problem, but it appear when using schema.validate function, but not in schema.validateAt. validationError.path has format TupleArray["0"] instead of TupleArray[0].

alexdee2007 commented 11 months ago

Hi, I've also faced this problem, but it appear when using schema.validate function, but not in schema.validateAt. validationError.path has format TupleArray["0"] instead of TupleArray[0].

Hi, yes it is. I'm using schema.validate. I had to write something like this to make the application work correctly.

error.path = error.path?.replace(/\["([0-9]+)"\]/g, '[$1]');