colinhacks / zod

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

Add support for `base64url` strings #3711

Open marvinruder opened 1 month ago

marvinruder commented 1 month ago

The .base64() function validates strings that contain binary information encoded in Base 64. A modification of Base 64 that can safely be used in URLs and filenames is given by the base64url standard specified in RFC 4648 § 5. As summarized here,

it uses the same algorithm as the main standard, but differs in the following:

  • Replaces “+” by “-” (minus)
  • Replaces “/” by “_” (underline)
  • Does not require a padding character
  • Forbids line separators

I propose a method .base64url() that is similar to .base64(), but instead matches against a regular expression that describes base64url-encoded values.