Repository navigation
fix: percent-encode % in default query-string mode - #173
Merged
Merged
Conversation
`MINIMAL_QS_SET` never added `b'%'`, so a literal `%` in a string value or map key was emitted raw. Anything that looked like a percent escape was then decoded on the way back in: - `"%41"` round-tripped to `"A"`, `"100%25"` to `"100%"` - `"%AD0"` made `from_str` fail with `Err(Utf8(..))` on the crate's own output - the distinct map keys `"[x]"` and `"%5Bx%5D"` both serialized to `a[%5Bx%5D]=1` Adding `%` to the set makes the bracket escaping unambiguous and restores the round-trip contract. Form encoding was already correct -- `FORM_URLENCODED_SET` is built on `NON_ALPHANUMERIC`. The `edge_case_primitives` round-trip test missed this because its literal is `"!@#$%^&*()..."`, where `%` is followed by `^`, a non-hex byte; it now also covers `%` followed by hex digits. Fixes #170 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
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.
Fixes #170. Thanks @hey-jj for the very precise report — the root cause was exactly where you pointed.
The bug
MINIMAL_QS_SETinsrc/ser/encode.rsnever called.add(b'%'), so a literal%in a string value or map key was emitted raw in the default (non-form) mode. Anything that then looked like a percent escape got decoded on the way back in:"%41""A""100%25""100%""a%3Db""a=b""%AD0"Err(Utf8(..))— on the crate's own outputIt also broke the bracket escaping documented at
src/config.rs:120: the distinct map keys"[x]"and"%5Bx%5D"both serialized toa[%5Bx%5D]=1, soa[%5Bx%5D]=1was ambiguous.The fix
One line — add
%to the set. That makes%5B/%5Dan unambiguous escape and restores the round-trip contract:Form encoding was already correct —
FORM_URLENCODED_SETis built onNON_ALPHANUMERIC, which includes%.Tests
percent_signs_roundtripregression test covering values, map keys, the non-UTF-8 cases, and the key collision.edge_case_primitivesgains apercent_escapesfield. As the issue notes, the existing literal"!@#$%^&*()..."missed this because%is followed by^, a non-hex byte — the new field uses%followed by hex digits. Confirmed it fails on the round-trip assertion without the one-line fix.%→%25); full CI feature matrix, doctests, clippy and fmt all pass locally.Compatibility note
This changes serializer output for any value containing
%. Anything that was previously round-tripping throughserde_qsis unaffected (it was already corrupted); but a consumer that deliberately fed pre-encoded strings through the serializer and relied on the pass-through will now see them double-encoded. That pass-through was never a documented guarantee and was indistinguishable from the corruption above, so I think the patch bump is right — flagging it in case you disagree.🤖 Generated with Claude Code