Repository navigation
Conversation
Form-encoding mode eagerly rewrites percent-encoded brackets so that nested keys can still form structure, but it compared the two bytes after `%` against the literal uppercase `5B`/`5D`. Lowercase `%5b`/`%5d` fell through to the catch-all arm, so `abc%5bdef%5d=ghi` stayed a flat `abc[def]` key instead of nesting, and no error was raised. The hex digits of a percent-encoding are case-insensitive (RFC 3986 section 6.2.2.1), and this crate's own `char_to_hexdigit` already accepts both cases, so the two paths disagreed. Fixes samscott89#176
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 #176.
The bug
In form-encoding mode the parser eagerly rewrites percent-encoded brackets so that nested keys can still form structure, but it compares the two bytes after
%against literal uppercase byte strings:Lowercase
%5b/%5dfalls into the catch-all arm, so the key never becomes structure:The silent part is what makes it awkward to debug: deserialization does not fail, it just produces a flat key, so the caller sees a missing-field error somewhere further away from the cause.
Oracle
Two things agree against the current behaviour.
RFC 3986 section 6.2.2.1 states that the hexadecimal digits within a percent-encoding triplet are case-insensitive. And this crate already implements that rule one module over:
char_to_hexdigitinsrc/de/parse/decode.rsacceptsb'a'..=b'f'alongsideb'A'..=b'F'. So the decoder treats hex case-insensitively and the eager bracket rewrite does not — the two paths in the same crate disagree about the same input.The fix
Match on the byte pattern instead of a fixed byte string, accepting either case for the second digit. The
5is a digit and has no case.Tests
Added to
tests/test_regression.rs, following the convention of the existing entries there. It covers uppercase, lowercase, and mixed case in a single key, and then pins the boundary that matters for a change like this: a doubly-encoded bracket must not be rewritten into structure.abc%255Bdef%255D=ghistill yields the flat keyabc%5Bdef%5D, in either case, because the rewrite inspects the two bytes after%(25) and correctly declines. Without that assertion, a sloppier fix that matched too eagerly would pass.Verified red then green rather than only green — with the source change reverted, the new test fails as:
and passes with it applied. Full suite with the CI feature set:
cargo test --all-targets --features "actix4,warp,axum"all 13 test targets ok, 0 failed.cargo fmt --all --checkclean andcargo clippy --all-targets -F "actix4,warp,axum" -- -D warningsclean.This is independent of #177 (issue #175) — different file, different cause — so the two can be merged in either order.
Credit to @hey-jj for the report.
Disclosure: I use AI assistance in my work, and I review and verify everything before it goes out.