Repository navigation
fix(wkt): accept ProtoJSON Base64 variants - #7328
Conversation
Accept standard and URL-safe Base64 with optional padding when extracting BytesValue from Any Keep standard padded serialization and reject malformed encodings Add regression coverage for supported encodings and invalid input Fixes googleapis#6714
There was a problem hiding this comment.
Code Review
This pull request updates the BytesValue deserializer in src/wkt/src/wrappers.rs to accept both standard and URL-safe Base64 alphabets, with or without padding, aligning with ProtoJSON specifications. It also introduces comprehensive parameterized tests covering various valid and invalid Base64 encoding scenarios. I have no feedback to provide as the changes are well-implemented and include robust test coverage.
suzmue
left a comment
There was a problem hiding this comment.
Thanks for the PR! I just have one comment on the error path.
Use the URL-safe decoder only when the input contains '-' or '_', as in protobuf-go, so decoding errors describe the encoding that was used Reuse the padding-indifferent engines from base64 and cover the decoder selection with tests for both alphabets and underscore-only input
|
/gcbrun |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7328 +/- ##
==========================================
- Coverage 27.77% 27.77% -0.01%
==========================================
Files 177 177
Lines 22622 22625 +3
==========================================
Hits 6284 6284
- Misses 16338 16341 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/gcbrun I think the failures were related to the branch being out of date. Re-running. |
Accept standard and URL-safe Base64 with or without padding when extracting BytesValue from Any
Select the decoder from the input alphabet so decoding errors describe the encoding that was used
Keep serialization in standard padded Base64 and retain validation of malformed encodings
Reproduction
Confirmed on unmodified upstream revision 07bda02 using the public Any API
The standard padded input +/8= succeeded, while +/8 failed with Invalid padding and both -_8= and -_8 failed with Invalid symbol
All four inputs now decode to the expected bytes
Regression coverage
Nine of fourteen valid-input cases failed before the fix, all fourteen now pass
Cover both alphabets, zero to two padding characters, omitted padding, empty input, and canonical reserialization
Verify that invalid characters, invalid lengths, excess or embedded padding, and nonzero trailing bits are rejected
Assert that malformed standard and URL-safe inputs report the error from the matching decoder
Verification
cargo test --locked -p google-cloud-wkt --all-features
cargo clippy --locked -p google-cloud-wkt --all-targets -- -D warnings
cargo clippy --locked -p google-cloud-wkt --profile test -- -D warnings
cargo clippy --locked --all-features --no-deps -p google-cloud-wkt -- -D warnings -D missing_docs -D clippy::exhaustive_enums
cargo fmt --check
typos
git diff --check
Fixes #6714