fix(foundation): Fix Zod serde for Buffer32#23240
Merged
Merged
Conversation
spalladino
approved these changes
May 13, 2026
Contributor
spalladino
left a comment
There was a problem hiding this comment.
Looks good, but I'd argue the proper fix is replacing all this.SIZE with Buffer32.SIZE in Buffer32's static methods (today it's a mix).
Contributor
Author
|
It's true that using this in a class-static context smells weird. Will switch! |
## Summary - `Buffer32.fromString` and `fromBuffer28` referenced `this.SIZE`, which broke when the static method was called with a different `this` (e.g. passed unbound to `z.transform` in `schemas.Buffer32`, where `this.SIZE` became `undefined` and the length check threw `"Expected string to be NaN characters long, but was 64"`). - Replace remaining `this.SIZE` uses with `Buffer32.SIZE` so the static methods don't depend on call-site binding. The rest of the class already used `Buffer32.SIZE` — this just removes the mix. - Add a regression test that round-trips a random `Buffer32` through `schemas.Buffer32`.
bdd13cb to
4625734
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Buffer32.fromStringandfromBuffer28referencedthis.SIZE, which broke when the static method was called with a differentthis(e.g. passed unbound toz.transforminschemas.Buffer32, wherethis.SIZEbecameundefinedand the length check threw"Expected string to be NaN characters long, but was 64").this.SIZEuses withBuffer32.SIZEso the static methods don't depend on call-site binding. The rest of the class already usedBuffer32.SIZE— this just removes the mix.Buffer32throughschemas.Buffer32.