Skip to main content

Module quoting

Module quoting 

Source
Expand description

Percent-encoding with the same rules as Python’s yarl.

  • quote encodes a literal value: every character that isn’t allowed in the component, including %, is percent-encoded.
  • requote normalizes an already-encoded value: valid %XX escapes are kept (uppercased, or decoded when they encode an unreserved character), any other disallowed character is percent-encoded.
  • unquote decodes a value. Escapes that don’t form valid UTF-8 are kept as is.

All functions borrow the input if it doesn’t need to change.

use urly::quoting::{Component, quote, requote, unquote};

assert_eq!(quote("a b/100%", Component::Path), "a%20b/100%25");
assert_eq!(requote("a b/100%25%7e", Component::Path), "a%20b/100%25~");
assert_eq!(quote("a b&c=d", Component::QueryPart), "a+b%26c%3Dd");
assert_eq!(unquote("a+b%26c", Component::QueryPart), "a b&c");
assert_eq!(quote("a=b; c", Component::Opaque), "a%3Db%3B%20c");

Enums§

Component
The URL component a value belongs to; it selects the characters that are left unencoded.

Functions§

quote
Percent-encodes a literal value.
requote
Normalizes the percent-encoding of an already-encoded value.
unquote
Decodes a percent-encoded value.