Expand description
URL / IRI / URI helpers — url_encode, uri_to_iri, iri_to_uri,
escape_uri_path, filepath_to_uri, urlsafe_base64_encode /
_decode and friends. Pure std, so it is always compiled.
URL codec helpers: application/x-www-form-urlencoded decoding,
RFC 3986 percent encoding, and urlsafe base64.
URL decoders are an easy place to hide a security bug, so all of it lives here and a fix lands everywhere at once.
§Decoding rules
+becomes a space. This is the form convention, and every browser form encoder uses it.%XXwith two hex digits becomes that byte. Mixed case is fine.- A bad or truncated escape keeps the literal
%and parsing goes on, likeserde_urlencodedand RFC 3986 §2.1. - Bytes that are not valid UTF-8 become
U+FFFDthroughString::from_utf8_lossy. A single bad byte must not wipe the whole output.
This is not a full RFC 3986 decoder: it does not treat reserved
characters differently per URI part. Use url::Url to parse a whole
URL; use this for form bodies and query-string values.
Functions§
- escape_
uri_ path - Percent-encode the path part of a URI.
/is kept, so the path structure survives. - filepath_
to_ uri - Turn a filesystem path into a URI path. Windows
\separators become/. - iri_
to_ uri - Turn an IRI (RFC 3987) into a plain URI (RFC 3986) by
percent-encoding every byte outside the URI-safe set. Reserved
syntax characters such as
/,?,#and%are kept, so a URI the caller built stays parseable. - percent_
decode_ path - Decode one path segment:
%XXonly,+stays literal. - uri_
to_ iri - Turn a URI back into IRI form: decode the escapes that make valid Unicode, and keep the URI’s structure.
- url_
decode - Decode a
application/x-www-form-urlencodedstring. - url_
encode - Percent-encode every byte outside the RFC 3986 unreserved set
(alphanumeric and
-_.~). - urlsafe_
base64_ decode - Decode a URL-safe base64 string into raw bytes. Padding is
optional, so senders that include
=still work. - urlsafe_
base64_ encode - Base64-encode
byteswith the URL-safe alphabet and the=padding stripped, so the result drops into a URL path or query value with no escaping. Used for theuidb64part of/reset/<uidb64>/<token>/.