Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for base64url strings #3711

Closed
marvinruder opened this issue Aug 16, 2024 · 0 comments · Fixed by #3712
Closed

Add support for base64url strings #3711

marvinruder opened this issue Aug 16, 2024 · 0 comments · Fixed by #3712

Comments

@marvinruder
Copy link
Contributor

marvinruder commented Aug 16, 2024

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.

marvinruder added a commit to marvinruder/zod that referenced this issue Aug 16, 2024
marvinruder added a commit to marvinruder/zod that referenced this issue Aug 30, 2024
colinhacks pushed a commit to marvinruder/zod that referenced this issue Dec 10, 2024
colinhacks added a commit that referenced this issue Dec 10, 2024
* Add support for `base64url` strings

Fixes #3711

Signed-off-by: Marvin A. Ruder <[email protected]>

* Add comments

Signed-off-by: Marvin A. Ruder <[email protected]>

* Change test structure for `base64()`, `base64url()`

Signed-off-by: Marvin A. Ruder <[email protected]>

* Prettier

* Avoid test.each

---------

Signed-off-by: Marvin A. Ruder <[email protected]>
Co-authored-by: Colin McDonnell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant