pub fn ash_normalize_binding(
method: &str,
path: &str,
query: &str,
) -> Result<String, AshError>Expand description
Normalize a binding string to canonical form (v2.3.2+ format).
Bindings are in the format: METHOD|PATH|CANONICAL_QUERY
§Normalization Rules
- Method is uppercased
- Path must start with
/ - Path must not contain
?(usenormalize_binding_from_urlfor combined path+query) - Path is percent-decoded, normalized, then re-encoded (BUG-025 fix)
- Path has duplicate slashes collapsed (after decoding)
- Trailing slash is removed (except for root
/) - Query string is canonicalized (sorted, normalized)
- Parts are joined with
|(pipe) separator
§Path Normalization (BUG-025)
Paths are decoded before normalization to handle cases like:
/api/%2F%2F/users→ decoded →/api///users→ normalized →/api/users/api/caf%C3%A9→ decoded →/api/café→ re-encoded →/api/caf%C3%A9
§Error on Embedded Query
If the path parameter contains a ?, an error is returned to prevent
silent data loss. Use [normalize_binding_from_url] if you have a combined
path+query string.
§Example
use ash_core::ash_normalize_binding;
let binding = ash_normalize_binding("post", "/api//users/", "").unwrap();
assert_eq!(binding, "POST|/api/users|");
let binding_with_query = ash_normalize_binding("GET", "/api/users", "page=1&sort=name").unwrap();
assert_eq!(binding_with_query, "GET|/api/users|page=1&sort=name");
// Error if path contains '?'
assert!(ash_normalize_binding("GET", "/api/users?old=query", "new=query").is_err());