Repository navigation
fix(data): one percent-decoder, which needs two hex digits after % - #2154
Conversation
Five copies decoded %XX escapes; three used u8::from_str_radix, which
takes a sign, so %+1 and %-1 became a byte. All now call
rustgis_data::address::{percent_decode, form_decode, query_params}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
|
||
| /// One pass over `s`: an escape is `%` and exactly two hex digits ([`hex`] takes no sign), and | ||
| /// the bytes are made text only at the end, so a character escaped as several bytes decodes whole. | ||
| fn decode(s: &str, plus: bool) -> String { |
There was a problem hiding this comment.
Quality (confidence: medium-high): This adds a second byte-level escape decoder to address.rs, next to the existing decode_pass (line 35), which decoded_name already uses. The two are nearly identical, but they differ on \uXXXX escapes: decode_pass decodes them and decode does not. So the PR's "one decoder" claim doesn't hold, and a future fix to the %XX rule would have to be made in both places.
I'd fold the two into one scanner that takes the mode (form +, literal +, and whether \u is decoded), or at least note in the doc comment why paths, tokens and connection strings must not decode \u. I have not changed the behaviour in this review; the %XX fix itself looks correct.
There was a problem hiding this comment.
Fixed in 768fa18: percent_decode and form_decode are now modes of decode_pass, so every %XX decode in address.rs goes through one scanner. DecodeMode gained FormValue and Value, which leave \uXXXX as typed: a backslash in a path or password (C:\users\uabcd) is itself, while names being classified still decode it. The test covers that case. On the import nit: ui-egui has no direct rustgis-data dependency, so it reaches the module through rustgis_engine::data.
Code reviewBugs: None found. The Security: None found. Decoding still happens only after the credential and token paths already in place, and no new input source is added. Performance: None found. Allocation pattern matches the old copies. Quality:
AGENTS.md: Layering holds ( Concerns already raised: 0. There were no prior review threads. Change sizeCompared with main (merge base 656adeb to PR head 55832e8).
|
percent_decode and form_decode are now modes of decode_pass, which name classification already used; values never decode \uXXXX, names do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the |
| /// itself. An escape without two hex digits (`%zz`, `%+1`) stays as it is; bytes that aren't UTF-8 | ||
| /// become U+FFFD. | ||
| pub fn percent_decode(s: &str) -> String { | ||
| String::from_utf8_lossy(&decode_pass(s.as_bytes(), DecodeMode::Value)).into_owned() |
There was a problem hiding this comment.
AGENTS.md, Never silent (confidence: medium): percent_decode turns bytes that aren't UTF-8 into U+FFFD with no notice. The doc comment records this, but the rule asks for a notice when a reader approximates data. The old copies in pgconn, ui-egui and ogc_warp did the same, so this predates the PR. The PR now routes database passwords, sslrootcert paths, file:// paths and tokens through this one helper, so a password with invalid UTF-8 escapes will authenticate-fail with no message saying the bytes were replaced. The fix needs notice plumbing, since this helper returns a plain String. A caller that has a Session should check whether the input changed and report it through Session::notify, with one notice per kind and a count. I haven't suggested a code change because the notice has to come from the caller. No change is needed for the +/%XX fix itself, which looks correct.
There was a problem hiding this comment.
Leaving this out of this PR: the replacement predates it, and every decoder it replaces did the same, so no input decodes differently here. It is also not a read that drops data: these helpers decode addresses, passwords and paths, which the database clients and file APIs take as String, so bytes that aren't UTF-8 can't reach them either way. A password like that fails with the server's own authentication error. If a reader ever decodes data values through this, that caller should count and report the replacements.
Code reviewBugs: None found. I checked the new Security: None found. The one behaviour change is in ChatGPT and ArcGIS callback parsing, where a Performance: None found. The decoder is linear, and the Quality:
AGENTS.md:
Prior reviews: one earlier thread, on the duplicate decoder in Change sizeCompared: the whole PR against main (merge base 656adeb to PR head 768fa18).
|
Both were already strict copies of form_decode and percent_decode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code reviewI reviewed the eight changed files against the call sites they replace and the new Bugs
Security
Performance
Quality (nits, not posted; for the release quality pass)
AGENTS.md
Prior reviews: two earlier threads exist on this PR. The thread on lossy UTF-8 without a notice was answered by the PR author (MEMBER), and I found no evidence against that answer, so I left it alone. The thread asking for one shared decoder is resolved in 768fa18, and the merged Change sizeCompared: the whole PR against main (merge base 656adeb to PR head 3e6065c).
|
Summary
RustGIS decoded
%XXescapes in seven places, and they didn't agree on what an escape is:%+1gaveassistant::chatgpt::urldecode/query_paramstiles::arcgis_auth::decode_with/query_paramsdata::ogc_warp::unescapedata::source::pgconn::percent_decode%+1ui-egui::panes::percent_decodedfile://paths in the Sources pane%+1The first three hand the two characters after
%tou8::from_str_radix, which accepts a leading sign, so%+1and%-1decoded as a byte. The other two required two hex digits, as RFC 3986 does.This puts one decoder in
rustgis_data::address, next to the address helpers that already parse escapes strictly:percent_decode, where+is itself (paths, connection strings, tokens);form_decode, where+is a space (query strings and form bodies);query_params, built onform_decode.All five copies now call it, as do two more that were already strict:
tiles::s3::decode/decode_path(form and path modes) andmap::qgis::source::decode.chatgpt::query_paramsandarcgis_auth::query_paramsare re-exports, so their callers and tests are unchanged. Each caller keeps its+rule: the callbacks decode+as a space and a pasted portal token keeps it. An escape without two hex digits now stays as typed everywhere. Net −118 lines.Testing
address::tests::percent_escapes_need_two_hex_digits:%+1,%-1,%zzand a cut-off%4stay as typed;+in each mode; UTF-8 and invalid bytes;query_params.cargo test -p rustgis-data --libforaddress,source::andogc;-p rustgis-tiles --lib arcgis_auth;-p rustgis-assistant --lib.cargo clippy -p rustgis-data -p rustgis-tiles -p rustgis-assistant -p rustgis-ui-egui --all-targets -- -D warnings, and the wasm check for the crates belowapps/.Related issue
None; found in a maintainability sweep.
🤖 Generated with Claude Code
Summary by CodeRabbit
+to a space where form-style decoding applies.