URL
Links resolved the way a browser resolves them, from the standard’s current text, with the same shape as the JavaScript `URL` API.
What it does
- The WHATWG URL Standard: parsing against a base, every getter and setter the
URLinterface has, and origins. URLSearchParams.- Hosts, IDNA (UTS #46) and Punycode, with Unicode 18.0’s tables and normalization built in.
- An API shaped like JavaScript’s, so
url.pathname()here isurl.pathnamethere.
Add it
In Rust, add parsec-url (0.3.1 on crates.io); the library inside isparsec_url. Rust only. The other bindings resolve links through the HTML parser, not this API.
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");That's the first example in the crate's own documentation at the v0.3.1 tag, unchanged.cargo test runs it on every change, so it compiles and passes against the release you'd install. The API reference on docs.rs has the rest, and the getting started guide goes step by step.
Checked against the standards
These counts are the conformance baseline on Parsec's main branch, read when this page was built. Each release has to match or beat them: a suite that passes fewer cases, or fails more, stops the release.
| Suite | Pass | Fail | Skipped |
|---|---|---|---|
| web-platform-tests URL parsing | 904 | 0 | 0 |
| web-platform-tests URL origins | 421 | 0 | 0 |
| web-platform-tests URL setters | 284 | 0 | 0 |
| web-platform-tests ToASCII | 261 | 0 | 522 |
| web-platform-tests IDNA | 2,675 | 0 | 1 |
| web-platform-tests IDNA, removed cases | 20 | 0 | 0 |
| Unicode normalization | 20,172 | 0 | 0 |
Standards has every suite, where its data comes from, and why the failures and skips are what they are.
Where it stops
- web-platform-tests has one file of URL cases only JavaScript can express, every one a lone surrogate. A Rust string can’t hold one, so they don’t run.
The URL page in the docs goes through the API, the limits and the conformance details in full.