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

V2: Relax validation in BinaryWriter #877

Merged
merged 1 commit into from
Jun 4, 2024
Merged

Conversation

timostamm
Copy link
Member

BinaryWriter implements the Protobuf wire encoding. Its methods int32, uint32, float, fixed32, sfixed32, and sint32 validate that the numbers passed in meet the constraint of the numeric type. For example, a uint32 - an unsigned 32-bit integer - must not be negative.

The methods accept the TypeScript type number, but the implementation actually functions correctly if a string is passed, because of ECMAScript's implicit conversion.

This PR changes the validation to also accept a string, and covers the correct behavior with tests. The reason for this change is to make the BinaryWriter more useful outside of the protobuf-es runtime.

This PR does not change the method signatures. The intended use is still to pass in a number, the support for string is just for resilience.

@timostamm timostamm changed the title Relax validation in BinaryWriter V2: Relax validation in BinaryWriter Jun 4, 2024
@timostamm timostamm merged commit 11c5db0 into v2 Jun 4, 2024
8 checks passed
@timostamm timostamm deleted the tstamm/relax-assertions branch June 4, 2024 16:08
@timostamm timostamm mentioned this pull request Jun 4, 2024
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.

2 participants