zod icon indicating copy to clipboard operation
zod copied to clipboard

Add support for `base64url` strings

Open marvinruder opened this issue 1 year ago • 4 comments

Fixes #3711

marvinruder avatar Aug 16 '24 20:08 marvinruder

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
Latest commit f3039197bd299fd5eb078966e94f01ede10007d5
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.

netlify[bot] avatar Aug 16 '24 20:08 netlify[bot]

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.

marvinruder avatar Aug 16 '24 20:08 marvinruder

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)

rotu avatar Aug 30 '24 18:08 rotu

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 avatar Aug 30 '24 18:08 marvinruder

lgtm!

rotu avatar Sep 01 '24 03:09 rotu