Expand description
The WHATWG URL Standard: URLs with every getter and setter the URL
interface has, URLSearchParams, and the host, IDNA and Punycode
algorithms under them.
It’s written from the standard’s current text, IDNA (UTS #46) and NFC
included, with the Unicode 18.0 tables in src/tables.rs. The API has
the shape the standard’s JavaScript one has, so url.pathname() here is
url.pathname there. tests/wpt.rs runs the web-platform-tests URL
suite against it, every case of which passes.
use parsec_url::Url;
let base = Url::parse("https://example.com/a/b?x=1").unwrap();
let mut url = Url::parse_with_base("../c?q=two words#top", &base).unwrap();
assert_eq!(url.href(), "https://example.com/c?q=two%20words#top");
let mut params = url.search_params();
params.append("page", "2");
url.set_search_params(¶ms);
assert_eq!(url.search(), "?q=two+words&page=2");Modules§
- normalize
- Unicode Normalization Forms C and D (UAX #15), from the Unicode 18.0
character data: canonical decomposition, canonical ordering, and
canonical composition with the composition exclusions, with Hangul
syllables done by arithmetic. IDNA needs NFC;
tests/normalization.rsruns all of Unicode’s NormalizationTest.txt against both forms. - punycode
- RFC 3492 Punycode, one label at a time and without the
xn--prefix.
Structs§
- Invalid
Domain - A domain the URL Standard’s domain to ASCII rejects.
- Search
Params URLSearchParams: an ordered list of name-value pairs, read from and written asapplication/x-www-form-urlencoded.- Url
- A parsed URL. Getters and setters are named after the
URLinterface’s attributes and behave as they do: a setter given a value the spec rejects leaves the URL as it was.
Enums§
- Host
- A host as
Host::parsegives it: what a special URL’s host can be. - Parse
Error - Why a URL didn’t parse.
Functions§
- domain_
to_ ascii - The URL Standard’s domain parser, which the host parser runs:
"Bücher.example"becomes"xn--bcher-kva.example". An ASCII domain is only lowercased; any other goes through UTS #46 ToASCII. Either way the result can’t be empty or hold a forbidden domain code point. - domain_
to_ unicode - The URL Standard’s domain to Unicode, for showing a host to a person:
"xn--bcher-kva.example"becomes"bücher.example". A domain that UTS #46 ToUnicode records an error for comes back as it was.