Skip to main content

Module url_legacy

Module url_legacy 

Source
Expand description

The legacy url.parse / url.format API — a faithful port of Node’s lib/url.js Url.prototype.parse, Url.prototype.format and urlFormat.

This API predates (and disagrees with) the WHATWG URL parser in url.rs: it is a hand-rolled scanner with its own whitespace trimming, backslash rewriting, “simple path” fast path, auto-escaping table and slashed/hostless protocol sets. Reimplementing it from the documentation produces a parser that agrees on http://host/path and disagrees on everything else, so this is a line-for-line port of the JS instead, sharing the same field names and insertion order (protocol, slashes, auth, host, port, hostname, hash, search, query, pathname, path, href).

Node scans by UTF-16 code unit; this port scans by char. Every branch keys off ASCII delimiters, so the emitted strings match.

Structs§

Url
The parsed legacy URL. Every field is Option, mirroring the null-initialized Url instance; slashes is a tri-state (None = null).

Functions§

format_url
Port of Url.prototype.format. query_string is the already-stringified query object (Node runs querystring.stringify when query is an object); None means query was not an object.
format_value
url.format(urlObject) — a string is re-parsed first, a URL instance uses its href, and anything else goes through Url.prototype.format.
parse
Port of Url.prototype.parse. slashes_denote_host is the third url.parse argument. Errors correspond to the JS throw sites.
to_js
Build the JS Url-shaped object, preserving Node’s field insertion order.