0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-10 22:38:53 -05:00

Fix action form parsing for .nullish (#11452)

This commit is contained in:
Fugi 2024-07-17 05:23:30 -07:00 committed by Emanuele Stoppa
parent 83a41d7277
commit d14f5d9573
2 changed files with 7 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue where using .nullish() in a formdata Astro action would always parse as a string

View file

@ -124,8 +124,8 @@ export function formDataToObject<T extends z.AnyZodObject>(
const obj: Record<string, unknown> = {};
for (const [key, baseValidator] of Object.entries(schema.shape)) {
let validator = baseValidator;
if (baseValidator instanceof z.ZodOptional || baseValidator instanceof z.ZodNullable) {
validator = baseValidator._def.innerType;
while (validator instanceof z.ZodOptional || validator instanceof z.ZodNullable) {
validator = validator._def.innerType;
}
if (validator instanceof z.ZodBoolean) {
obj[key] = formData.has(key);