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 #3712

Merged
merged 5 commits into from
Dec 10, 2024

Conversation

marvinruder
Copy link
Contributor

Fixes #3711

Copy link

netlify bot commented Aug 16, 2024

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
🔨 Latest commit f303919
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/6757a3c8a490db000857914a
😎 Deploy Preview https://deploy-preview-3712--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@marvinruder
Copy link
Contributor Author

The new method should probably also be added to https://github.com/colinhacks/zod/blob/main/README.md#strings, but I didn’t want to predict the version number under which this feature may be released.

src/types.ts Show resolved Hide resolved
src/types.ts Show resolved Hide resolved
src/__tests__/string.test.ts Outdated Show resolved Hide resolved
@rotu
Copy link
Contributor

rotu commented Aug 30, 2024

I like the spirit, but I'm not sure I like the implementation. If the idea is "parse, don't validate", then maybe it would be more on-brand to provide a transform to get at the represented binary data, rather than just validate the string unchanged. (of course the same goes for the existing z.string().base64() method)

@marvinruder
Copy link
Contributor Author

I like the spirit, but I'm not sure I like the implementation. If the idea is "parse, don't validate", then maybe it would be more on-brand to provide a transform to get at the represented binary data, rather than just validate the string unchanged. (of course the same goes for the existing z.string().base64() method)

Parsing the encoded data into a buffer would be an interesting opt-in feature given that people are only interested in the binary data. My main use case for base64url at the moment is Web Authentication, and a popular library implementing that standard expects base64url-encoded strings in many of its interfaces, so I am only interested in validation, as the library already does the parsing and expects unparsed strings. It would be great if Zod would (continue to) offer validation-only processing of base64(url)-encoded strings.

@marvinruder marvinruder force-pushed the marvinruder/issue3711 branch from 070c899 to 05c4922 Compare August 30, 2024 19:06
@rotu
Copy link
Contributor

rotu commented Sep 1, 2024

lgtm!

marvinruder and others added 4 commits December 9, 2024 17:59
Fixes colinhacks#3711

Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
@colinhacks colinhacks force-pushed the marvinruder/issue3711 branch from 13bc1db to 8976023 Compare December 10, 2024 02:00
@colinhacks colinhacks merged commit b85686a into colinhacks:main Dec 10, 2024
13 checks passed
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 this pull request may close these issues.

Add support for base64url strings
3 participants