-
-
Notifications
You must be signed in to change notification settings - Fork 268
Closed
Labels
bugSomething isn't workingSomething isn't workingintendedThe behavior is expectedThe behavior is expectedpriorityThis has priorityThis has priority
Description
While building a base type which maps empty strings to undefined, I stumbled about the minLength
& maxLength
functions crashing, when passed an undefined value which was wrapped in a nonOptional
or nonNullish
:
import * as v from 'valibot';
const String = v.nonOptional(
v.pipe(
v.string(),
v.transform((val) => val?.trim() || undefined),
),
);
const Password = v.pipe(String, v.minLength(6))
const Schema = v.object({
password: Password
});
const result = v.safeParse(Schema, {
password: "",
});
console.log(result);
This actually crashes the execution, even though safe Parse is used:
[error]: TypeError: Cannot read properties of undefined (reading 'length')
at ~validate (https://valibot.dev/assets/Cb45s_t9-index.min.js:1:18263)
at ~validate (https://valibot.dev/assets/Cb45s_t9-index.min.js:1:64883)
at ~validate (https://valibot.dev/assets/Cb45s_t9-index.min.js:1:45222)
at Module.Ae (https://valibot.dev/assets/Cb45s_t9-index.min.js:1:65578)
at about:srcdoc:152:18
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingintendedThe behavior is expectedThe behavior is expectedpriorityThis has priorityThis has priority