pub fn canonicalize_query(input: &str) -> Result<String, AshError>Expand description
Canonicalize a URL query string according to ASH specification.
§Canonicalization Rules (9 MUST rules)
- MUST parse query string after
?(or use full string if no?) - MUST split on
&to get key=value pairs - MUST handle keys without values (treat as empty string)
- MUST percent-decode all keys and values
- MUST apply Unicode NFC normalization
- MUST sort pairs by key lexicographically (byte order)
- MUST preserve order of duplicate keys
- MUST re-encode with uppercase hex (%XX)
- MUST join with
&separator
§Example
use ash_core::canonicalize_query;
let input = "z=3&a=1&b=hello%20world";
let output = canonicalize_query(input).unwrap();
assert_eq!(output, "a=1&b=hello%20world&z=3");
// With leading ?
let input2 = "?z=3&a=1";
let output2 = canonicalize_query(input2).unwrap();
assert_eq!(output2, "a=1&z=3");