colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.92k stars 1.18k forks source link

z.string().base64() validation matches non-base64 strings #3680

Closed EvgenyWas closed 3 months ago

EvgenyWas commented 3 months ago

Actual behavior: The z.string().base64() validation matches non-base64 strings even when a string is empty.

Expected behavior: The z.string().base64() validation matches only valid base64 strings.

Environment:

Reproduction: https://zod-playground.vercel.app?appdata=N4IgzgxgFgpgtgQxALhALwHRgC4CcCWAdgOYAUAlBgEYJgwBsALBQNwgA0IAbggDYCuMMCgDaIAOTiOEwgjgwpncfkTFFEmnSkBdTlxi4w%2BAPaEUIAMwYATFYAcIAL5A

UPD: According to the spec I see the empty string is valid base64. Additionally, I see it's tested with the empty string as well, but I think the rest of values in my repro are still non-valid base64 strings.