Function normalize_uri_path_component

Source
pub fn normalize_uri_path_component(
    path_component: &str,
) -> Result<String, SignatureError>
Expand description

Normalize the path component according to RFC 3986. This performs the following operations:

  • Alpha, digit, and the symbols -, ., _, and ~ (unreserved characters) are left alone.
  • Characters outside this range are percent-encoded.
  • Percent-encoded values are upper-cased (%2a becomes %2A)
  • Percent-encoded values in the unreserved space (%2D, %2E, %30-%39, %5F, %41-%5A, %61-%7A, %7E) are converted to normal characters.
  • Plus-encoded spaces (+) are converted to %20.

§Errors

If a percent encoding is incomplete or is invalid, SignatureError::InvalidURIPath is returned.

§Example

assert_eq!(normalize_uri_path_component("a b").unwrap(), "a%20b");
assert_eq!(normalize_uri_path_component("%61b").unwrap(), "ab");