Skip to content

Commit 6d7b9d6

Browse files
committed
Enhance date handling in buildDateArbitrary function to prevent invalid dates
1 parent 42328ef commit 6d7b9d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/builder/date.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function buildDateArbitrary(schema: UnknownValibotSchema, path: string) {
1010
const pipes = "pipe" in schema ? schema.pipe : undefined;
1111

1212
if (!pipes || !Array.isArray(pipes)) {
13-
return fc.date();
13+
return fc.date({ noInvalidDate: true });
1414
}
1515

1616
for (const pipe of pipes.filter((pipe) => pipe.kind === "validation")) {
@@ -44,7 +44,9 @@ export function buildDateArbitrary(schema: UnknownValibotSchema, path: string) {
4444
}
4545
}
4646

47-
const constraints: { min?: Date; max?: Date } = {};
47+
const constraints: { min?: Date; max?: Date; noInvalidDate?: boolean } = {
48+
noInvalidDate: true,
49+
};
4850

4951
if (minValue instanceof Date) {
5052
constraints.min = minValue;

0 commit comments

Comments
 (0)