| Title: | Parse, Clean, and Normalize URLs |
|---|---|
| Description: | A lightweight toolkit for extracting structured information from URLs. Includes functions for parsing, normalizing protocols, extracting domains, and constructing clean URLs. Domain and public-suffix extraction is delegated to the 'pslr' package, which implements the Public Suffix List from <https://publicsuffix.org>. Punycode and IDNA encoding is handled by the 'punycoder' package, and IP address facts by the 'raddr' package. |
| Authors: | Bart Turczynski [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-8788-7980>) |
| Maintainer: | Bart Turczynski <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 3.1.0.9000 |
| Built: | 2026-12-02 13:12:29 UTC |
| Source: | https://gitlab.com/bart-turczynski/rurl |
Deprecated. canonical_join() is deprecated in this release
and will be removed in rurl 4.0.0. Every call emits a warning of class
"rurl_canonical_join_deprecated"; results are unchanged. Use one of
these instead:
To join on URL identity, the url_*_join() family
(url_inner_join, url_left_join,
url_right_join, url_full_join,
url_semi_join, url_anti_join).
To keep matching on cleaned URLs, build the key with
get_clean_url and merge on it:
A$k <- get_clean_url(A$URL) B$k <- get_clean_url(B$URL) merge(A, B, by = "k", incomparables = NA)
incomparables = NA stops URLs that have no clean form from
matching each other, as canonical_join() never matches them.
The recipe is not a drop-in replacement:
it is an inner join; add all.x = TRUE,
all.y = TRUE or all = TRUE for a left, right or
full join;
it keeps every row that shares a key, where
canonical_join() keeps the first (collision =
"first");
it also matches rows with a warning-* parse status
that have a clean form, which canonical_join() leaves
unmatched (join_parse_status = "ok");
merge() sorts by the key unless sort = FALSE,
and names the columns k, URL.x and URL.y
rather than JoinKey, A and B with the
_A/_B suffixes.
canonical_join( data_A, data_B, col_A = "URL", col_B = "URL", suffix_A = "_A", suffix_B = "_B", name_A = NULL, name_B = NULL, join = c("inner", "left", "right", "full"), collision = c("first", "all", "error"), on_parse_error = c("keep", "drop", "error"), join_parse_status = c("ok", "ok_or_warning"), ... )canonical_join( data_A, data_B, col_A = "URL", col_B = "URL", suffix_A = "_A", suffix_B = "_B", name_A = NULL, name_B = NULL, join = c("inner", "left", "right", "full"), collision = c("first", "all", "error"), on_parse_error = c("keep", "drop", "error"), join_parse_status = c("ok", "ok_or_warning"), ... )
data_A |
A data frame containing URLs for the left side of the join. |
data_B |
A data frame containing URLs for the right side of the join. |
col_A |
Character string, the name of the column in |
col_B |
Character string, the name of the column in |
suffix_A |
Character string, suffix to append to |
suffix_B |
Character string, suffix to append to |
name_A |
Character string, the name of the output column holding the
original |
name_B |
Character string, the name of the output column holding the
original |
join |
Join type: |
collision |
How to handle duplicate canonical keys within inputs.
|
on_parse_error |
How to handle URLs that fail canonicalization.
|
join_parse_status |
Which parse statuses yield joinable canonical keys.
|
... |
Additional arguments forwarded to |
Performs a join between two data frames by canonicalizing URLs to a shared
"clean" format using safe_parse_urls and then matching on
that key.
A data frame representing the join. The output includes:
The original URL columns (named via name_A / name_B,
or after the input expressions when those are NULL).
JoinKey: the canonicalized URL used for matching.
All other columns from data_A and data_B with
suffixes applied.
Returns an empty data frame with the expected structure if no matches are found or if inputs are invalid.
canonical_join() keys the join on the cleaned presentation string
(clean_url), so every cleaning or display argument forwarded through
... currently changes which rows match. Those arguments do not
participate in URL identity; they are legacy behavior retained for a
deprecation window. Supplying any of
protocol_handling, www_handling, source,
tld_source, case_handling, trailing_slash_handling,
index_page_handling, path_normalization,
subdomain_levels_to_keep, host_encoding, path_encoding,
port_handling, engine, profile, or any query cleaning
dial (query_handling, params_keep, params_drop,
params_case_sensitive, sort_params,
empty_param_handling, decode_plus)
emits one warning per call, of class
"rurl_legacy_join_dial_warning". Results are unchanged: the warning
is purely additive, so no caller is silently re-matched.
The input and interpretation arguments url_standard,
scheme_acceptance, scheme_policy, and
scheme_relative_handling are legitimate inputs to identity and never
warn.
Because the condition is classed, it can be silenced selectively without
hiding other warnings:
suppressWarnings(canonical_join(A, B, www_handling = "strip"),
classes = "rurl_legacy_join_dial_warning").
The deprecation warning (class "rurl_canonical_join_deprecated")
fires on every call, first, before any argument is checked. A call that also
forwards a legacy presentation dial then gets the dial warning (class
"rurl_legacy_join_dial_warning") as well, unchanged. The two are
separate conditions, so muting one class leaves the other visible: code that
already mutes "rurl_legacy_join_dial_warning" keeps working and now
also sees the deprecation. To mute both, name both classes:
suppressWarnings(canonical_join(A, B, www_handling = "strip"),
classes = c("rurl_canonical_join_deprecated",
"rurl_legacy_join_dial_warning")).
A <- data.frame( URL = c("https://Example.com/page", "https://example.com/other"), ValA = 1:2, stringsAsFactors = FALSE ) B <- data.frame( URL = c( "https://example.com/page?utm_source=nl", "https://example.com/missing" ), ValB = c("x", "y"), stringsAsFactors = FALSE ) # Default canonicalization lower-cases the host and drops the query, so the # first row of each side shares one canonical key. Deprecated: this call # warns. canonical_join(A, B) # The same match, built from get_clean_url() keys. A$k <- get_clean_url(A$URL) B$k <- get_clean_url(B$URL) merge(A, B, by = "k", incomparables = NA) # Or join on URL identity: the query is part of identity, so these differ. url_inner_join(A[, c("URL", "ValA")], B[, c("URL", "ValB")], by = "URL")A <- data.frame( URL = c("https://Example.com/page", "https://example.com/other"), ValA = 1:2, stringsAsFactors = FALSE ) B <- data.frame( URL = c( "https://example.com/page?utm_source=nl", "https://example.com/missing" ), ValB = c("x", "y"), stringsAsFactors = FALSE ) # Default canonicalization lower-cases the host and drops the query, so the # first row of each side shares one canonical key. Deprecated: this call # warns. canonical_join(A, B) # The same match, built from get_clean_url() keys. A$k <- get_clean_url(A$URL) B$k <- get_clean_url(B$URL) merge(A, B, by = "k", incomparables = NA) # Or join on URL identity: the query is part of identity, so these differ. url_inner_join(A[, c("URL", "ValA")], B[, c("URL", "ValB")], by = "URL")
Tabular companion to is_valid_host: for each URL, reports the
parsed host, its get_host_type classification, a logical column
for each requested policy rule, and a reasons list-column naming the
host facts observed. Useful for auditing a URL set before choosing what to
keep — see why a host is not a practical web/SEO host, not just that
it is not.
check_hosts( url, rules = c("url", "dns", "web", "registrable", "seo"), url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )check_hosts( url, rules = c("url", "dns", "web", "registrable", "seo"), url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )
url |
A character vector of URLs. |
rules |
A character vector of one or more rules to score, drawn from
|
url_standard |
Standard profile governing host interpretation:
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
Like is_valid_host this is a policy layer, not parser
conformance and not a conformance oracle: it never changes how a URL parses
and the absence of a reasons token is not a validity guarantee (see
is_valid_host's “A policy layer” section).
A data.frame with one row per input URL (input order
preserved): url, host (the parsed host, or NA),
host_type, one logical column per requested rule (NA when the
URL has no host to judge; the "url" rule's column is named
url_valid so it does not shadow the input url column), and
reasons — a list-column whose i-th
element is a character vector of the host facts observed for that URL
(character(0) when none). The reasons evidence is reported
for the row as a whole, independent of which rules were requested,
and combines the host-shape diagnostics that fired (see
get_url_diagnostics) with the policy tokens
"ip-literal", "not-registrable", and
"underscore-label".
is_valid_host, get_host_type,
get_url_diagnostics.
urls <- c( "http://example.com", # registrable domain "http://_dmarc.example.com", # valid DNS owner name, not a web hostname "http://a+b.example", # valid RFC reg-name, neither web nor dns "http://-example.com", # hyphen hygiene failure "http://a..com", # empty label "http://localhost", # web hostname, but not registrable "http://192.168.0.1", # IP literal "http://xn--nxasmq6b.example.com" # IDN (A-label) ) check_hosts(urls) # Score a single rule, or a subset: check_hosts(urls, rules = c("web", "dns")) # RFC 3986 reg-name semantics instead of whatwg: check_hosts("http://2130706433", url_standard = "rfc3986")urls <- c( "http://example.com", # registrable domain "http://_dmarc.example.com", # valid DNS owner name, not a web hostname "http://a+b.example", # valid RFC reg-name, neither web nor dns "http://-example.com", # hyphen hygiene failure "http://a..com", # empty label "http://localhost", # web hostname, but not registrable "http://192.168.0.1", # IP literal "http://xn--nxasmq6b.example.com" # IDN (A-label) ) check_hosts(urls) # Score a single rule, or a subset: check_hosts(urls, rules = c("web", "dns")) # RFC 3986 reg-name semantics instead of whatwg: check_hosts("http://2130706433", url_standard = "rfc3986")
Tabular companion to get_scheme and
get_scheme_class, and the scheme-axis counterpart of
check_hosts: for each URL, reports the parsed scheme, its
special/non-special classification, whether it falls inside the built-in
web-acceptance set, an optional allowed column scored against a
caller-supplied allowlist, and a reasons list-column naming the
scheme facts observed.
check_schemes( url, allowed_schemes = NULL, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("general", "web") )check_schemes( url, allowed_schemes = NULL, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("general", "web") )
url |
A character vector of URLs. |
allowed_schemes |
Optional character vector of schemes the caller will
act on, compared case-insensitively. When supplied, the result gains a
logical |
url_standard |
Standard profile governing scheme interpretation:
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
Like check_hosts this is a policy layer, not parser
conformance: it never changes how a URL parses. Restricting which schemes
your application will act on is the caller's decision, and this helper
supplies the facts to make it — it does not make it for you.
Every token names something observable about the parse. None is a risk
label, and none is intended as one: whether a scheme is safe depends on what
the caller does with the URL, which this package cannot observe. A
scp: URL is unremarkable to a mirroring tool and unacceptable in an
HTTP fetcher, and no property of the string distinguishes those cases.
A data.frame with one row per input URL (input order
preserved): url, scheme (the parsed scheme, lowercased, or
NA), scheme_class ("special", "non-special" or
"missing-or-error"), web_scheme (is the scheme one of the
five scheme_acceptance = "web" admits), allowed (only when
allowed_schemes is supplied), and reasons — a list-column
whose i-th element is a character vector of the scheme facts observed
(character(0) when none). The tokens are "no-scheme",
"special-scheme", "non-special-scheme",
"outside-web-acceptance", "no-authority" and
"not-in-allowlist".
"no-authority" marks a URL that has a scheme but carries no
authority: mailto:[email protected], javascript:alert(1),
foo:bar. It is reported when all three hold: the input has no
// after its scheme colon; the parse record's host is
NA; and, under url_standard = "whatwg", the scheme is
non-special. The last condition exists because WHATWG gives every
special-scheme URL a host, with or without //:
http:example.com parses to host example.com, and
file:foo is the same URL as file:///foo. Under
url_standard = "rfc3986" an authority exists only after //
(RFC 3986 section 3), so http:example.com does get the token there.
A row with no scheme never gets it: without a scheme there is no
scheme-driven authority question to answer.
The token is computed from the parse. For
mailto:[email protected] the parse record's host is
NA and its path is [email protected], and
get_host gives NA too.
scheme_acceptance defaults to "general" here, not to the
package-wide "web". Auditing which schemes a URL set carries is
pointless under an acceptance mode that has already collapsed every
non-web scheme into a parse error.
check_hosts for the host axis,
get_scheme_class, get_url_diagnostics.
urls <- c( "https://example.com/a", # special, inside web acceptance "ftp://example.com/a", # special, inside web acceptance "scp://host/a", # non-special, outside web acceptance "smb://server/share", # non-special, outside web acceptance "mailto:[email protected]", # non-special, opaque path "javascript:alert(1)", # non-special, opaque path "notaurl" # no scheme ) check_schemes(urls) # Score against the schemes an application will actually act on: check_schemes(urls, allowed_schemes = c("https", "http"))urls <- c( "https://example.com/a", # special, inside web acceptance "ftp://example.com/a", # special, inside web acceptance "scp://host/a", # non-special, outside web acceptance "smb://server/share", # non-special, outside web acceptance "mailto:[email protected]", # non-special, opaque path "javascript:alert(1)", # non-special, opaque path "notaurl" # no scheme ) check_schemes(urls) # Score against the schemes an application will actually act on: check_schemes(urls, allowed_schemes = c("https", "http"))
Renders each URL as a string a person can read safely: credentials are
redacted, invisible and bidirectional-override code points are made visible
as <U+XXXX> tokens, percent-encoded delimiters are left encoded so decoding
cannot fabricate structure, and an internationalized host is shown in both
its Unicode and its ASCII (punycode) spelling whenever the two differ.
format_url(url, engine = NULL)format_url(url, engine = NULL)
url |
A character vector of URLs. |
engine |
Optional |
A character vector the same length as url. NA_character_ for
input the WHATWG parser does not accept.
format_url() output is display only. It is not reparsable, has no
round-trip guarantee, and must never be fed back into serialize_url(), into
a comparison key, or into anything that treats it as an address. Use
serialize_url() for a standard-exact full string and get_clean_url() for
the cleaning surface.
serialize_url() for the standard-exact full string,
get_clean_url() for the cleaning surface, and safe_parse_url() for the
parsed components.
# Credentials are redacted, never shown. format_url("https://user:[email protected]/a") # Percent-encoded delimiters stay encoded: decoding them would fabricate # structure that the URL does not have. format_url("https://example.com/a%2Fb?x=a%26b%3Dc") # An internationalized host is shown in both spellings when they differ. format_url("https://xn--mnchen-3ya.de/p") # Invisible and bidirectional-override code points are made visible. format_url("https://example.com/p?q=x#%E2%80%AE%E2%80%8Bevil") # A byte no valid UTF-8 sequence can contain is emitted, not decoded. format_url("https://example.com/%FF%00") # Input the WHATWG parser rejects is NA, not a guess. format_url("example.com/x")# Credentials are redacted, never shown. format_url("https://user:[email protected]/a") # Percent-encoded delimiters stay encoded: decoding them would fabricate # structure that the URL does not have. format_url("https://example.com/a%2Fb?x=a%26b%3Dc") # An internationalized host is shown in both spellings when they differ. format_url("https://xn--mnchen-3ya.de/p") # Invisible and bidirectional-override code points are made visible. format_url("https://example.com/p?q=x#%E2%80%AE%E2%80%8Bevil") # A byte no valid UTF-8 sequence can contain is emitted, not decoded. format_url("https://example.com/%FF%00") # Input the WHATWG parser rejects is NA, not a guess. format_url("example.com/x")
This function returns the cleaned version of the URLs after applying
protocol, www, case, and trailing slash handling rules. By default the result
is a normalized canonical key composed of scheme, host, and path only; port
is dropped (port_handling = "exclude"), and fragment/userinfo are
always excluded (use get_port, get_fragment, or
get_userinfo for those). A URL that carried credentials is
silently collapsed to its credential-free spelling by default
(credential_handling = "strip"); pass
credential_handling = "reject" to get NA for such a row
instead (RFC 3986 sections 3.2.1, 7.5 and 7.6; ADR 0017 row 12).
get_clean_url( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), case_handling = "lower_host", trailing_slash_handling = "none", index_page_handling = "keep", path_normalization = "none", scheme_relative_handling = "keep", subdomain_levels_to_keep = NULL, host_encoding = "keep", path_encoding = "keep", query_handling = c("drop", "filter", "allow", "keep"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, sort_params = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE, port_handling = c("exclude", "keep", "strip_default", "strip_all"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL, profile = NULL, credential_handling = c("strip", "reject"), path_normalisation = NULL )get_clean_url( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), case_handling = "lower_host", trailing_slash_handling = "none", index_page_handling = "keep", path_normalization = "none", scheme_relative_handling = "keep", subdomain_levels_to_keep = NULL, host_encoding = "keep", path_encoding = "keep", query_handling = c("drop", "filter", "allow", "keep"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, sort_params = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE, port_handling = c("exclude", "keep", "strip_default", "strip_all"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL, profile = NULL, credential_handling = c("strip", "reject"), path_normalisation = NULL )
url |
A character vector containing URLs to be parsed. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
source |
Which PSL source to use: "all", "private", or "icann".
Subdomain trimming depends on which section is consulted, so pass
|
case_handling |
A character string specifying how to handle the case of the cleaned URL. Defaults to "lower_host", the RFC 3986 §6.2.2.1 normalization (scheme and host are case-insensitive and folded to lowercase; the path is case-sensitive and preserved).
|
trailing_slash_handling |
A character string specifying how to handle
trailing slashes in the path of
|
index_page_handling |
A character string specifying how to handle
index/default pages in
|
path_normalization, path_normalisation
|
How to normalize path
structure. Defaults to "none".
|
scheme_relative_handling |
How to handle URLs starting with "//". Defaults to "keep".
|
subdomain_levels_to_keep |
An integer or NULL. Determines how many
levels of subdomains are kept,
in addition to any 'www.' prefix handled by
|
host_encoding |
How to present the host in
Under
|
path_encoding |
How to present the path percent-encoding in
|
query_handling |
A character string controlling whether (and how) the
query string is included in
In every non-"drop" mode the surviving query is re-encoded canonically
(uppercase percent-hex, spaces as |
params_keep |
Character vector of parameter-name globs (only |
params_drop |
Character vector of parameter-name globs to add to the
built-in denylist in "filter" mode, or |
params_case_sensitive |
Logical (default |
sort_params |
Logical (default |
empty_param_handling |
One of "keep" (default) or "drop". "drop" removes
empty-valued params (e.g. |
decode_plus |
Logical (default |
port_handling |
A character string controlling whether the port
appears in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
profile |
Optional named profile bundling several knobs at once: |
credential_handling |
How
There is no "keep": |
The query string is dropped by default (query_handling = "drop"), so
the historical scheme/host/path output is byte-identical. Pass
query_handling = "keep", "filter", or "allow" (with the
companion params_* / sort_params / empty_param_handling
/ decode_plus arguments) to retain a shaped query on the cleaned URL;
the engine is the same one safe_parse_url and
get_query use, so
get_clean_url(u, query_handling = "filter") equals
safe_parse_url(u, query_handling = "filter")$clean_url.
The port is included only when port_handling != "exclude"; see
safe_parse_url for the full port_handling semantics.
A character vector of cleaned URLs.
A cleaned URL is an SEO and deduplication product, not an identity function
and not a standard's serialization. It is deliberately lossy: the
fragment and userinfo are always dropped, the query is dropped by default,
and the cleaning policies (www_handling,
trailing_slash_handling, index_page_handling, subdomain
trimming, port_handling) exist precisely to collapse URLs that differ.
Distinct URLs therefore map to the same cleaned string, so this is never an
identity function and never round-trips back to its input.
Two kinds of knob do the collapsing, and profile = "seo" carries
both (RUL-017). Normalization knobs apply what a standard says
yields the same resource: the WHATWG parse, host case and UTS #46
rendering, and removal of a default port. Editorial knobs assert a
fact about the site that no standard settles: https, no www., no
trailing slash, no index page, no query. Only the editorial knobs can
change the addressed resource; see url_profile for the
per-knob classification.
It is also not the surface rurl's standards-conformance claims are measured on. When identity or conformance is the goal, use a different surface:
serialize_url — the selected standard's own
full-string serialization, credentials and fragment included. This is the
substrate the conformance claims are measured on.
get_url_key (with url_key_policy) and the
url_join family — resource identity for deduplicating,
grouping, matching and joining. No cleaning option can reach a key byte.
path_encoding is a presentation knob and does not select a standard's
path identity; url_standard does. On the path axis the selector means:
url_standard = "rfc3986" applies RFC 3986 section 6.2.2.2
percent-encoding normalization: a triplet encoding an unreserved
byte (A-Z, a-z, 0-9, -, ., _,
~) is decoded to that byte, and every other triplet — reserved
bytes such as %2F, %3F, %23, and non-ASCII bytes
such as %C3 — is left encoded with its hex digits uppercased.
It is applied before dot-segment removal, so an encoded dot segment
(%2E / %2E%2E) resolves like a literal one.
url_standard = "whatwg" (the default; NULL means
the same) preserves existing percent-triplets byte-for-byte, hex case
included, and resolves encoded dot segments without any decode.
That normalization is part of the path a URL denotes.
path_encoding = "keep" (the default) preserves it verbatim, and
"encode" keeps it while escaping the octets the standard does not
allow in a path. "decode" layers a readable form on top: it decodes
unreserved and well-formed UTF-8 triplets only, so a reserved octet such
as %2F stays encoded and never becomes a path-separating /.
See vignette("url-standard").
serialize_url for a standard's full-string
serialization (the conformance-bearing surface), get_url_key
and url_join for resource identity and joining, and
safe_parse_url for the parsed components.
get_clean_url("Example.COM/Path") # Default lower_host: host folds, path kept get_clean_url( "Example.COM/Path", case_handling = "lower", # shapes clean_url only under "whatwg" trailing_slash_handling = "keep" ) # Keeping the input's case is RFC 3986 syntax with no normalization: get_clean_url("http://Example.COM/Path", profile = "rfc-syntax") get_clean_url( "Example.COM/Path/", case_handling = "upper", trailing_slash_handling = "strip" ) get_clean_url("http://example.com", www_handling = "strip") get_clean_url( "http://deep.sub.domain.example.com/path", subdomain_levels_to_keep = 0 ) # -> "http://example.com/path" get_clean_url( "http://www.deep.sub.domain.example.com/path", subdomain_levels_to_keep = 1, www_handling = "strip" ) # -> "http://domain.example.com/path" get_clean_url( "http://www.deep.sub.domain.example.com/path", subdomain_levels_to_keep = 1, www_handling = "keep" ) # -> "http://www.domain.example.com/path" # Query dropped by default (byte-identical to earlier releases): get_clean_url("http://example.com/p?utm_source=nl&id=42") # -> "http://example.com/p" # Strip trackers, keep contentful params: get_clean_url( "http://example.com/p?utm_source=nl&id=42", query_handling = "filter" ) # -> "http://example.com/p?id=42" # Lossy by design: different URLs clean to the same string, and the cleaned # string is not what a standard would serialize. u <- c("http://u:[email protected]/a#frag", "http://example.com/a?q=1") get_clean_url(u) # -> both "http://example.com/a" # Ask for NA instead of a silently collapsed credential-bearing URL: get_clean_url(u, credential_handling = "reject") # -> NA, "http://example.com/a" serialize_url(u[1]) # The identity surface keeps them apart: the query is identity, the # fragment and userinfo are not. k <- get_url_key(u) k[1] == k[2] # -> FALSE # RFC 3986 section 6.2.2.2 on the path: unreserved triplets decode, # reserved ones stay encoded. get_clean_url("http://example.com/a%7Eb%2Fc", url_standard = "rfc3986") # -> "http://example.com/a~b%2Fc" get_clean_url("http://example.com/a%7Eb%2Fc", url_standard = "whatwg") # -> "http://example.com/a%7Eb%2Fc"get_clean_url("Example.COM/Path") # Default lower_host: host folds, path kept get_clean_url( "Example.COM/Path", case_handling = "lower", # shapes clean_url only under "whatwg" trailing_slash_handling = "keep" ) # Keeping the input's case is RFC 3986 syntax with no normalization: get_clean_url("http://Example.COM/Path", profile = "rfc-syntax") get_clean_url( "Example.COM/Path/", case_handling = "upper", trailing_slash_handling = "strip" ) get_clean_url("http://example.com", www_handling = "strip") get_clean_url( "http://deep.sub.domain.example.com/path", subdomain_levels_to_keep = 0 ) # -> "http://example.com/path" get_clean_url( "http://www.deep.sub.domain.example.com/path", subdomain_levels_to_keep = 1, www_handling = "strip" ) # -> "http://domain.example.com/path" get_clean_url( "http://www.deep.sub.domain.example.com/path", subdomain_levels_to_keep = 1, www_handling = "keep" ) # -> "http://www.domain.example.com/path" # Query dropped by default (byte-identical to earlier releases): get_clean_url("http://example.com/p?utm_source=nl&id=42") # -> "http://example.com/p" # Strip trackers, keep contentful params: get_clean_url( "http://example.com/p?utm_source=nl&id=42", query_handling = "filter" ) # -> "http://example.com/p?id=42" # Lossy by design: different URLs clean to the same string, and the cleaned # string is not what a standard would serialize. u <- c("http://u:[email protected]/a#frag", "http://example.com/a?q=1") get_clean_url(u) # -> both "http://example.com/a" # Ask for NA instead of a silently collapsed credential-bearing URL: get_clean_url(u, credential_handling = "reject") # -> NA, "http://example.com/a" serialize_url(u[1]) # The identity surface keeps them apart: the query is identity, the # fragment and userinfo are not. k <- get_url_key(u) k[1] == k[2] # -> FALSE # RFC 3986 section 6.2.2.2 on the path: unreserved triplets decode, # reserved ones stay encoded. get_clean_url("http://example.com/a%7Eb%2Fc", url_standard = "rfc3986") # -> "http://example.com/a~b%2Fc" get_clean_url("http://example.com/a%7Eb%2Fc", url_standard = "whatwg") # -> "http://example.com/a%7Eb%2Fc"
Extracts the registered domain name from a URL (e.g., "example.com"). Relies on the Public Suffix List.
get_domain( url, protocol_handling = "keep", www_handling = "none", subdomain_levels_to_keep = NULL, source = c("all", "private", "icann"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )get_domain( url, protocol_handling = "keep", www_handling = "none", subdomain_levels_to_keep = NULL, source = c("all", "private", "icann"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
subdomain_levels_to_keep |
An integer or NULL. Determines how many
levels of subdomains are kept,
in addition to any 'www.' prefix handled by
|
source |
Which PSL source to use: "all", "private", or "icann". |
host_encoding |
How to present the host in
Under
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
A character vector of domain names.
get_domain("http://www.example.co.uk/path")get_domain("http://www.example.co.uk/path")
Extracts the fragment component of a URL. The value is never
percent-decoded. Under url_standard = "whatwg" it carries the
standard's percent-encoded spelling (the fragment percent-encode set is
applied, so a double-quote inside the fragment becomes %22); under
url_standard = "rfc3986" it is the raw source spelling, exactly as
written in the URL.
get_fragment( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_fragment( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A character vector of fragments.
get_fragment("http://example.com/path#section") get_fragment("http://example.com/p#a\"b", url_standard = "whatwg")get_fragment("http://example.com/path#section") get_fragment("http://example.com/p#a\"b", url_standard = "whatwg")
Extracts the host component of a URL.
get_host( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), subdomain_levels_to_keep = NULL, case_handling = c("lower", "keep", "upper", "lower_host"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )get_host( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), subdomain_levels_to_keep = NULL, case_handling = c("lower", "keep", "upper", "lower_host"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
source |
Which PSL source to use: "all", "private", or "icann".
Subdomain trimming depends on which section is consulted, so pass
|
subdomain_levels_to_keep |
An integer or NULL. Determines how many
levels of subdomains are kept,
in addition to any 'www.' prefix handled by
|
case_handling |
How to handle casing of the returned host. Defaults to
"lower", which folds the host exactly as "lower_host" does. The host is a
parsed component, and |
host_encoding |
How to present the host in
Under
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
A URL with no host gives NA. That includes a mailto: URL such
as mailto:[email protected]: a non-special scheme with no // is
an opaque path (WHATWG URL Standard; RFC 3986 section 3), so it has no host,
as safe_parse_url's host column says. Read a
recipient's domain with get_mailto_recipients.
A character vector of URL hosts.
get_host("http://sub.example.com:8080") get_host( "http://www.two.one.example.com", subdomain_levels_to_keep = 1 ) # Result: "www.one.example.com" get_host( "http://www.two.one.example.com", www_handling = "strip", subdomain_levels_to_keep = 1 ) # Result: "one.example.com" get_host( "http://www.two.one.example.com", www_handling = "keep", subdomain_levels_to_keep = 1 ) # Result: "www.one.example.com" get_host( "http://three.two.one.example.com", subdomain_levels_to_keep = 0 ) # Result: "example.com" get_host( "http://www.three.two.one.example.com", subdomain_levels_to_keep = 0 ) # Result: "www.example.com"get_host("http://sub.example.com:8080") get_host( "http://www.two.one.example.com", subdomain_levels_to_keep = 1 ) # Result: "www.one.example.com" get_host( "http://www.two.one.example.com", www_handling = "strip", subdomain_levels_to_keep = 1 ) # Result: "one.example.com" get_host( "http://www.two.one.example.com", www_handling = "keep", subdomain_levels_to_keep = 1 ) # Result: "www.one.example.com" get_host( "http://three.two.one.example.com", subdomain_levels_to_keep = 0 ) # Result: "example.com" get_host( "http://www.three.two.one.example.com", subdomain_levels_to_keep = 0 ) # Result: "www.example.com"
Companion helper for the url_standard selector: reports the host
type of each URL as exactly one of "domain", "ipv4",
"ipv6", "ipvfuture", "reg-name", or "missing".
"ipvfuture" is an RFC 3986 IPvFuture literal such as [v1.x],
which only "rfc3986" parses. Unlike a raw host
string, host_type is a function of both the host and the
selected standard: the numeric host 2130706433 is a "reg-name"
under "rfc3986" but an "ipv4" address under "whatwg".
Callers reading the result must therefore know which selector produced it.
get_host_type( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )get_host_type( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )
url |
A character vector of URLs. |
url_standard |
Standard profile governing host interpretation:
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
The metadata is intentionally exposed through this helper rather than as a
column on safe_parse_urls or a field on
safe_parse_url, keeping those functions' output shapes fixed
(ADR 0006).
A character vector the same length as url, each element one of
the host_type tokens above, or NA for a row that cannot be
classified under the selected standard.
NA means exactly one thing: this row is unclassifiable
under the selected standard. An all-NA result is evidence about
the input, not about the call.
get_url_diagnostics, get_parse_verdicts,
safe_parse_url
get_host_type("http://example.com/", url_standard = "rfc3986") get_host_type("http://2130706433/", url_standard = "whatwg")get_host_type("http://example.com/", url_standard = "rfc3986") get_host_type("http://2130706433/", url_standard = "whatwg")
Companion helper (ADR 0006) that reports structural, per-recipient
facts about the recipients in the positional to of a
mailto: URL — the comma-separated addr-spec list before the
? (RFC 6068 section 2). Recipients carried in to/cc/
bcc hfields are RFC 5322 address-lists and are deliberately
out of scope; only the positional list is analyzed.
get_mailto_recipients( url, url_standard = "rfc3986", scheme_policy = c("infer", "require"), scheme_acceptance = c("general", "web"), smtp_wire = FALSE )get_mailto_recipients( url, url_standard = "rfc3986", scheme_policy = c("infer", "require"), scheme_acceptance = c("general", "web"), smtp_wire = FALSE )
url |
A character vector of URLs. Non- |
url_standard |
Standard profile passed to the general parser. A
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
smtp_wire |
Logical; when |
Each fact names the grammar it was judged against. The left of the
addr-spec is classified as an RFC 6068 local-part and,
independently, the right is classified both as RFC 6068 mailto domain
vocabulary and as an SMTP (RFC 5321) mailbox right-hand side — these are
distinct grammars, so no single column spans them. Public-suffix knowledge is
reported separately and is explicitly non-validating: a known suffix
is not mailbox validity.
A data.frame (always, including for length-1 or all-empty
input) with one row per positional-to recipient and columns:
urlthe source URL the recipient came from.
recipient_index1-based index of the recipient within that URL's positional list.
mailto_local_part_rawthe recipient's local-part as it
stands in the URL's path, before any percent-decoding
("a%00zz"), so a local-part classified "invalid" is
still at hand. Under "rfc3986" that is the input's own
spelling; under "whatwg" it is the spelling the standard's
parse gives the path (a non-ASCII character is percent-encoded as
UTF-8, and a tab or newline is removed). NA
when the recipient has no single structural @.
mailto_local_part_formRFC 6068 local-part form:
"dot-atom-text", "quoted-string", "invalid", or
"indeterminate". RFC 6068 section 2 forbids RFC 5322's
obs-local-part and NO-WS-CTL (a C0 control other
than a null octet, tab, line feed or carriage return, or U+007F) and
whitespace in a local-part, so of RFC 5322's obsolete forms (section
4.1) only obs-qp before a null octet, a backslash then
%00 inside the quotes, is a "quoted-string"; RFC 5321
(section 4.1.2) has no obsolete forms, so such a local-part has no
SMTP wire projection ("unavailable").
mailto_domain_rawthe recipient's domain (the right of
the addr-spec) as it stands in the URL's path, before any
percent-decoding, on the same terms as
mailto_local_part_raw; NA exactly where that column is.
This is where a recipient's domain is read: a mailto: URL has
no host, so get_host gives NA for it.
mailto_domain_formRFC 6068 domain form:
"ascii-dot-atom-text", "idna2008-domain",
"bracketed-domain", "invalid", or
"indeterminate".
smtp_mailbox_rhs_syntax_formRFC 5321 mailbox RHS form,
independent of the mailto grammar and of DNS: "domain",
"address-literal", "invalid", or
"indeterminate".
public_suffix_knownTRUE/FALSE whether the
domain's public suffix is known to the PSL (non-validating);
NA when the RHS is not a domain form.
smtp_domain_wire_form(opt-in) "ascii-domain",
"a-label-domain", "u-label-domain",
"address-literal", or "unavailable".
smtp_envelope_wire_mode(opt-in) "ascii",
"smtputf8", or "unavailable".
smtp_envelope_address_requires_smtputf8(opt-in) logical;
NA when no wire projection could be made.
smtp_local_part_length_ok(opt-in) logical, serialized
local-part at most 64 octets; NA when unavailable.
smtp_direct_forward_path_fits(opt-in) logical, the octet
length of "<" + Mailbox + ">" is at most 256; NA when
unavailable. The familiar 254 is the RFC 3696 EID 1690 derivation of
this path limit, not a standalone production.
parse_statusthe source URL's parse status, as
safe_parse_urls reports it (see the corresponding
section); the same for every recipient of that URL.
url_diagnosticsa list-column whose element is the
character vector of the source URL's
get_url_diagnostics tokens (character(0) when
none). A token is a fact, not always a fault: a mailto: URL
that parses usually carries
"transform-skipped-ineligible-scheme", so select on
parse_status, not on an empty list.
These are selected structural facts, not
a conformance oracle and never a validator. A recipient's classification
never turns a parse into an error, and the absence of an invalid
value does not imply the address is deliverable or fully RFC-conformant.
No DNS resolution or deliverability check is performed.
The recipients are read from the
mailto: path whether or not the URL parses under
url_standard, so a URL the standard rejects still yields its
recipients, for diagnosis. Each row says whether the URL itself parsed:
parse_status is the URL's safe_parse_urls status and
url_diagnostics its get_url_diagnostics tokens,
under the same url_standard, scheme_policy and
scheme_acceptance. Under "rfc3986", mailto:a@bücher.de
yields a recipient whose domain is "idna2008-domain", with
parse_status "error" and the token
"unicode-outside-rfc3986-uri": RFC 3986 (sections 2, 2.5) and
RFC 6068 (section 2) write a non-ASCII character only percent-encoded as
UTF-8, and mailto:a@b%C3%BCcher.de parses. Filter on
parse_status to keep only the recipients of URLs that parse.
Set smtp_wire = TRUE to
additionally compute the SMTP transport facts that require an actual
serialized wire projection of the address (octet-length limits per RFC 5321
section 4.5.3.1, and the SMTPUTF8 envelope mode per RFC 6531/6530). These
are octet facts on the UTF-8 wire bytes, distinct from the syntax
classifications above and from DNS. When smtp_wire = FALSE (the
default) the five smtp_* wire columns are still present but carry
the "unavailable"/NA sentinel; the same sentinel is used for
a recipient whose address cannot be projected (an invalid mailbox).
The positional list is tokenized on the
raw (still percent-encoded) source before decoding, so an encoded
comma (%2C) is never a recipient separator and an encoded quote or
bracket (%22, %5B/%5D) still protects a raw comma;
each field is then percent-decoded exactly once and classified. A field
whose decoded octets are not valid UTF-8 is classified "invalid",
and so is a domain holding %00 (a null octet). A local-part
admits a null octet only as RFC 5322's obsolete quoted-pair (section
4.1, obs-qp), inside a quoted-string: the local-part of
mailto:%22%5C%00%[email protected] is a "quoted-string", while
a%00zz and %22%00%22 are "invalid".
A mailto: URL
with no // is an opaque path and has no host (WHATWG URL Standard;
RFC 3986 section 3), so get_host, get_user,
get_domain and get_host_type report none for
it. Its recipients, each one's local-part and domain, are read here.
get_url_diagnostics, safe_parse_url
get_mailto_recipients("mailto:[email protected]", scheme_acceptance = "general") get_mailto_recipients( "mailto:[email protected],\"b,c\"@example.org", scheme_acceptance = "general" ) # opt-in SMTP wire-projection facts get_mailto_recipients("mailto:[email protected]", scheme_acceptance = "general", smtp_wire = TRUE)get_mailto_recipients("mailto:[email protected]", scheme_acceptance = "general") get_mailto_recipients( "mailto:[email protected],\"b,c\"@example.org", scheme_acceptance = "general" ) # opt-in SMTP wire-projection facts get_mailto_recipients("mailto:[email protected]", scheme_acceptance = "general", smtp_wire = TRUE)
The status is a single value collapsed from three independent facts — URL
syntax, admission policy, and the Public Suffix List annotation — so it is
a lossy view of them. The guaranteed loss: a structural syntax
failure and a policy rejection both report "error". Call
get_parse_verdicts when you need to tell those apart, or to
read the PSL result as a typed annotation state rather than as a warning.
Nothing here is deprecated — the layered accessor is purely additive.
get_parse_status( url, protocol_handling = "keep", www_handling = "none", subdomain_levels_to_keep = NULL, source = c("all", "private", "icann"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_parse_status( url, protocol_handling = "keep", www_handling = "none", subdomain_levels_to_keep = NULL, source = c("all", "private", "icann"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs to be parsed. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
subdomain_levels_to_keep |
An integer or NULL. Determines how many
levels of subdomains are kept,
in addition to any 'www.' prefix handled by
|
source |
Which PSL source to use: "all", "private", or "icann".
Warning statuses such as |
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A character vector with the parse status of each URL: one of
"ok", "ok-ftp", "ok-scheme-relative",
"warning-no-tld", "warning-invalid-tld",
"warning-public-suffix", "warning-userinfo" (a scheme-less
input carrying userinfo, e.g. "[email protected]"), or
"error". See safe_parse_url for the full semantics.
get_parse_verdicts for the unprojected layers
get_parse_status( c("http://example.com", "ftp://example.com", "mailto:[email protected]") ) get_parse_status(c("http://example.com", "not-a-url")) get_parse_status("http://example.com", source = "icann")get_parse_status( c("http://example.com", "ftp://example.com", "mailto:[email protected]") ) get_parse_status(c("http://example.com", "not-a-url")) get_parse_status("http://example.com", source = "icann")
Companion helper that separates the three independent questions
get_parse_status collapses into one value: did the input
present well-formed URL syntax (layer 1), was the parsed object admitted
under the active policy (layer 2), and what did the Public Suffix List
annotation find (layer 3).
get_parse_verdicts( url, url_standard = "whatwg", protocol_handling = c("keep", "none", "strip", "http", "https"), scheme_relative_handling = c("keep", "http", "https", "error"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), tld_source = c("all", "private", "icann") )get_parse_verdicts( url, url_standard = "whatwg", protocol_handling = c("keep", "none", "strip", "http", "https"), scheme_relative_handling = c("keep", "http", "https", "error"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), tld_source = c("all", "private", "icann") )
url |
A character vector of URLs. |
url_standard |
Standard profile governing interpretation:
|
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_relative_handling |
How to handle URLs starting with "//". Defaults to "keep".
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
tld_source |
Which TLD source to use for TLD extraction: "all", "icann", or "private". Defaults to "all". |
The single parse_status value is a lossy projection of these
three. The guaranteed loss is that a structural syntax failure and a policy
rejection both surface as "error": under the default
scheme_acceptance = "web", "mailto:[email protected]" and
"http://" are both "error", but the first is
layer2_policy_verdict = "rejected-scheme" (rurl declined to accept the
scheme) while the second is layer1_syntax_verdict = "fail" (it did not
parse). Recovering that distinction is what this helper is for.
Like the other companion helpers this never widens the
safe_parse_url frame — the parse table keeps its 18 columns
and the verdicts live here. Layers 1 and 2 describe the parse that
actually occurred under the selected standard ("whatwg" by
default), so projecting the reported layers reproduces the reported
parse_status.
A data frame with one row per element of url and three
character columns: layer1_syntax_verdict,
layer2_policy_verdict, and layer3_annotation_state.
Layer 1 — syntax ("pass" / "fail"). Whether a
syntax failure was observed. "pass" is the absence of an
observed failure, not a proof of conformance — a row the admission gate
rejected before any parse ran reports its rejection in layer 2 and is not
additionally reported as a syntax failure.
Layer 2 — policy ("admitted",
"admitted-scheme-relative", "admitted-ftp",
"rejected-scheme", "warn-userinfo"). Whether the object is
admitted under the active scheme_acceptance /
scheme_relative_handling / userinfo policy, and with what note.
"rejected-scheme" rejects; "warn-userinfo" accepts with a
note; the admitted* values accept.
Layer 3 — annotation ("not-applicable",
"known", "unknown", and the currently unproduced
"not-requested", "invalid-input", "dependency-error").
The PSL registrability fact as a typed state rather than a bare
NA, and never fatal: a host with no public suffix is a
"unknown" annotation, not a parse failure. A host form with no
registrable-domain concept at all — an IP literal, a file: host,
an opaque authority — is "not-applicable", never "unknown".
get_parse_status, get_url_diagnostics,
safe_parse_url
# Both are parse_status "error" -- for entirely different reasons. get_parse_verdicts(c("mailto:[email protected]", "http://")) # A PSL miss is an annotation state, never a fatal verdict. get_parse_verdicts("http://example.invalidtld/")# Both are parse_status "error" -- for entirely different reasons. get_parse_verdicts(c("mailto:[email protected]", "http://")) # A PSL miss is an annotation state, never a fatal verdict. get_parse_verdicts("http://example.invalidtld/")
Extracts the password component of a URL. The value is never
percent-decoded. Under url_standard = "whatwg" it carries the
standard's percent-encoded spelling (the userinfo percent-encode set is
applied, so a ":" inside the password becomes %3A); under
url_standard = "rfc3986" it is the raw source spelling, exactly as
written in the URL. This is the same contract as get_user.
get_password( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_password( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A character vector of passwords.
get_password("ftp://user:[email protected]/file.txt") get_password("http://u:p:[email protected]/", url_standard = "whatwg")get_password("ftp://user:[email protected]/file.txt") get_password("http://u:p:[email protected]/", url_standard = "whatwg")
Extracts the path component of a URL.
get_path( url, protocol_handling = "keep", case_handling = c("lower_host", "keep", "lower", "upper"), trailing_slash_handling = c("none", "keep", "strip"), index_page_handling = c("keep", "strip"), path_normalization = c("none", "collapse_slashes", "dot_segments", "both"), path_encoding = c("keep", "encode", "decode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", path_normalisation = NULL )get_path( url, protocol_handling = "keep", case_handling = c("lower_host", "keep", "lower", "upper"), trailing_slash_handling = c("none", "keep", "strip"), index_page_handling = c("keep", "strip"), path_normalization = c("none", "collapse_slashes", "dot_segments", "both"), path_encoding = c("keep", "encode", "decode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", path_normalisation = NULL )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
case_handling |
How to handle casing of the returned path. Defaults to
"lower_host", which preserves the path's original casing (paths are
case-sensitive per RFC 3986 §6.2.2.1), as "keep" does. The path is a parsed
component, and |
trailing_slash_handling, index_page_handling
|
Accepted for
compatibility; neither changes the returned path. They shape |
path_normalization, path_normalisation
|
How to normalize path
structure. Defaults to "none".
|
path_encoding |
How to present the path percent-encoding in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A character vector of URL paths.
get_path("http://example.com/some/path?query=1")get_path("http://example.com/some/path?query=1")
Extracts the port component of a URL.
get_port( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_port( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
Under url_standard = "whatwg" a port equal to the scheme's default is
not part of the parsed URL (the standard discards it during parsing),
so "http://example.com:80/" reports NA rather than 80.
Under url_standard = "rfc3986" the written port is reported as-is,
up to 2147483647, the largest R integer: a larger port makes the URL a
parse error, so NA (RUL-036). This is distinct from
port_handling, a
presentation dial that governs whether a port is rendered into
clean_url; the two are independent.
An integer vector of ports.
get_port("http://example.com:8080/path") get_port("http://example.com:80/path", url_standard = "whatwg")get_port("http://example.com:8080/path") get_port("http://example.com:80/path", url_standard = "whatwg")
Extracts the query component of a URL, optionally parsing it into a list.
get_query( url, protocol_handling = "keep", format = c("string", "list"), decode = TRUE, query_handling = c("keep", "drop", "filter", "allow"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, sort_params = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE, scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_query( url, protocol_handling = "keep", format = c("string", "list"), decode = TRUE, query_handling = c("keep", "drop", "filter", "allow"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, sort_params = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE, scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
format |
Return format: "string" (default) or "list" for parsed elements. |
decode |
Logical; if TRUE (default), decodes the query. For
|
query_handling |
A character string controlling whether (and how) the
query string is included in
In every non-"drop" mode the surviving query is re-encoded canonically
(uppercase percent-hex, spaces as |
params_keep |
Character vector of parameter-name globs (only |
params_drop |
Character vector of parameter-name globs to add to the
built-in denylist in "filter" mode, or |
params_case_sensitive |
Logical (default |
sort_params |
Logical (default |
empty_param_handling |
One of "keep" (default) or "drop". "drop" removes
empty-valued params (e.g. |
decode_plus |
Logical (default |
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
The underlying parse preserves the raw query string byte-for-byte (a bare
key such as ?flag stays flag, not flag=). By default this accessor
still percent-decodes the string form for readability (decode = TRUE), but
only the triplets that name an unreserved ASCII character or well-formed
non-ASCII UTF-8. Every other ASCII triplet stays encoded, reserved ones such
as %26 (&), %3D (=) and %23 (#) included, because only an
unreserved octet's triplet is equivalent to the character it encodes (RFC
3986 sections 2.2 and 6.2.2.2; under the WHATWG URL Standard the query is a
percent-encoded string in which & separates pairs). The list form
(format = "list") decodes its keys and values differently; see decode.
Pass decode = FALSE to obtain the raw query exactly as written in the URL.
Under url_standard = "whatwg" the underlying query carries the standard's
percent-encoded spelling (the query percent-encode set is applied, so a
literal space becomes %20); under url_standard = "rfc3986" or no
selector it is the raw source spelling. That distinction shows with
decode = FALSE, and under decode = TRUE in the string form wherever a
triplet stays encoded: a literal apostrophe reads a=it%27s under
"whatwg" and a=it's under "rfc3986".
The filtering arguments (query_handling, params_keep, params_drop,
params_case_sensitive, sort_params, empty_param_handling,
decode_plus) share the engine used by get_clean_url, but
default to query_handling = "keep" here: an accessor returns the query as
found unless you ask it to filter. When no filtering or reordering is
requested (the default profile), the output is byte-for-byte identical to
earlier releases except that the string form keeps every ASCII triplet
outside the unreserved set encoded (RFC 3986 section 2.2); once you opt in,
the surviving params are selected first and only then rendered per
format/decode. With decode_plus = TRUE, a + in a value becomes a
space while %20 stays encoded, so a=x+y%20z reads a=x y%20z.
A character vector (format="string") or list (format="list"). In
the string form a present but empty query (https://example.com/?) is
"" and an absent one (https://example.com/) is NA, as the WHATWG URL
query state and RFC 3986 section 3.4 tell them apart; query_handling = "drop" gives "" for any present query and NA for an absent one. The
list form gives an empty list for both.
The query column of safe_parse_urls() stays NA for both (ADR 0012).
Because decode = TRUE is the default, this accessor can return
non-ASCII characters that the URL held only as percent-encoded UTF-8, such
as U+0085 (%C2%85) or U+2028 (%E2%80%A8), which a single-line consumer
may split on. The string form keeps every other ASCII triplet encoded, so
its CR, LF and %00 stay as written. The list form (format = "list")
decodes every triplet in its keys and values except %00, so %0D%0A
comes back as CR and LF there. Do not assume the result is single-line or
free of control characters. Treat it as untrusted input: do not interpolate
it into a header, a log line, a shell command, or a SQL statement without
escaping it for that sink. Pass decode = FALSE when you want the query
exactly as written, with no decoding step at all.
get_query("http://example.com/path?a=1&b=2") get_query(c("http://example.com/?", "http://example.com/")) get_query("http://example.com/path?a=1&b=2", format = "list") # Drop trackers, keep contentful params: get_query( "http://example.com/?utm_source=nl&id=42", query_handling = "filter" ) # Canonical (re-encoded) form: get_query( "http://example.com/?a=1%262", query_handling = "keep", decode = FALSE )get_query("http://example.com/path?a=1&b=2") get_query(c("http://example.com/?", "http://example.com/")) get_query("http://example.com/path?a=1&b=2", format = "list") # Drop trackers, keep contentful params: get_query( "http://example.com/?utm_source=nl&id=42", query_handling = "filter" ) # Canonical (re-encoded) form: get_query( "http://example.com/?a=1%262", query_handling = "keep", decode = FALSE )
Extracts the scheme (protocol) of a URL.
get_scheme( url, protocol_handling = "keep", scheme_relative_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_scheme( url, protocol_handling = "keep", scheme_relative_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_relative_handling |
How to handle URLs starting with "//". Defaults to "keep".
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
By default (scheme_acceptance = "web") only rurl's web-scheme
allowlist parses, so an opaque scheme such as mailto: or tel:
yields NA. Pass scheme_acceptance = "general" (which requires
an explicit url_standard) to run the general parser, under which those
schemes resolve and their scheme string is returned.
The result is always the parsed scheme. protocol_handling only
changes how clean_url presents the scheme, so it no longer moves
this component: get_scheme("ftp://h/x", protocol_handling = "https")
is "ftp", and a scheme-less host is "http" under every value.
A character vector of URL schemes.
get_scheme("https://example.com") get_scheme( "mailto:[email protected]", url_standard = "rfc3986", scheme_acceptance = "general" )get_scheme("https://example.com") get_scheme( "mailto:[email protected]", url_standard = "rfc3986", scheme_acceptance = "general" )
Companion helper for the url_standard selector: reports whether each
URL's resolved scheme is a WHATWG “special scheme” ("special"),
one rurl supports but WHATWG does not treat specially ("non-special"),
or absent/unparseable ("missing-or-error" – an unsupported scheme, a
scheme-relative URL under the default scheme_relative_handling =
"keep", or an input that failed to parse at all).
get_scheme_class( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )get_scheme_class( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )
url |
A character vector of URLs. |
url_standard |
Standard profile under which each URL is parsed before
its scheme is classified: |
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
Unlike get_host_type, the classification itself does not vary
between "rfc3986" and "whatwg" – “special scheme” is a
WHATWG concept describing a fixed property of the scheme string, not
something RFC 3986 redefines. url_standard still matters: the
resolved scheme this classification reads is itself produced by a
profile-dependent parse.
Within rurl's allowlist (http/https/ftp/ftps/
file), http, https, ftp, and file are
WHATWG special schemes; ftps (FTP-over-TLS, rurl's own addition) is
not. This is metadata only – it does not add ws/wss to
rurl's allowed schemes and does not change what
safe_parse_url accepts.
Under the default scheme_acceptance = "web" an opaque scheme such as
mailto: is outside rurl's web allowlist and classifies as
"missing-or-error". Pass scheme_acceptance = "general" to run
the general parser, under which such a scheme resolves and classifies as
"non-special" (it is not a WHATWG special scheme).
A character vector the same length as url, each element one
of "special", "non-special", or "missing-or-error".
Never NA. Every element receives one of the three tokens
above — input that is unparseable, scheme-less, empty or NA
classifies as "missing-or-error" rather than falling through to
NA.
get_scheme_class("http://example.com/", url_standard = "whatwg") get_scheme_class("ftps://example.com/", url_standard = "whatwg") get_scheme_class("//example.com/path", url_standard = "whatwg") get_scheme_class( "mailto:[email protected]", url_standard = "rfc3986", scheme_acceptance = "general" )get_scheme_class("http://example.com/", url_standard = "whatwg") get_scheme_class("ftps://example.com/", url_standard = "whatwg") get_scheme_class("//example.com/path", url_standard = "whatwg") get_scheme_class( "mailto:[email protected]", url_standard = "rfc3986", scheme_acceptance = "general" )
Extracts the subdomain component of a URL.
get_subdomain( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), include_www = FALSE, format = c("string", "labels"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )get_subdomain( url, protocol_handling = "keep", www_handling = "none", source = c("all", "private", "icann"), include_www = FALSE, format = c("string", "labels"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
source |
Which PSL source to use: "all", "private", or "icann". |
include_www |
Logical; if FALSE (default), removes a leading
|
format |
Return format: "string" (default) or "labels" for a character vector of labels. |
host_encoding |
How to present the host in
Under
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
A character vector (format="string") or list of label vectors (format="labels").
get_subdomain("http://www.blog.example.co.uk") get_subdomain("http://www.blog.example.co.uk", format = "labels")get_subdomain("http://www.blog.example.co.uk") get_subdomain("http://www.blog.example.co.uk", format = "labels")
Uses safe_parse_url internally to extract the TLD, benefiting from all memoization layers for improved performance.
get_tld( url, source = c("all", "private", "icann"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )get_tld( url, source = c("all", "private", "icann"), host_encoding = c("keep", "idna", "unicode"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL )
url |
A character vector of URLs. |
source |
Which TLD source to use: "all", "icann", or "private". |
host_encoding |
How to present the host in
Under
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
A character vector of TLDs.
get_tld("example.com")get_tld("example.com")
Companion helper for the url_standard selector: reports the
non-fatal validation/safety facts rurl observed while parsing each
URL (for example an IPv4 host written in a numeric or non-decimal shorthand,
or a path segment carrying an encoded reserved byte). Diagnostics are facts,
not policy: they are emitted keyed to host/path shape in both
standard modes so a security-sensitive consumer can reject a footgun URL
regardless of which selector it chose, while a link-graph consumer can ignore
them. The complete token vocabulary is enumerated below under
Diagnostic vocabulary (canonical).
get_url_diagnostics( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )get_url_diagnostics( url, url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )
url |
A character vector of URLs. |
url_standard |
Standard profile governing interpretation:
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
A single URL can carry several diagnostics, so the return shape is not a
plain scalar-per-URL vector (see Value). parse_status stays
coarse; diagnostics are never encoded into it.
Two tokens report why a URL failed rather than a fact about one that
parsed. The first is unicode-outside-rfc3986-uri. Under
url_standard = "rfc3986" a directly written non-ASCII character in any
component is a parse error, because RFC 3986 admits only US-ASCII (section 2)
and writes non-ASCII data as percent-encoded UTF-8 octets (section 2.5); a
host is an ASCII reg-name (section 3.2.2). Write ä as
%C3%A4, or parse Unicode input with url_standard = "whatwg".
rurl has no RFC 3987 (IRI) mode. The token fires only where that advice
holds: the row's twin, each non-ASCII octet written as its %XX
triplet, parses under the same options. A row that also fails for another
reason (a scheme-less input that is not host-like, scheme_policy =
"require", a scheme the "web" acceptance refuses, an ASCII grammar
fault, or a row led by a non-ASCII character, whose twin then has no scheme)
reports no token. A row that reports this token reports it alone, under
either scheme_acceptance.
The second is port-out-of-integer-range. RFC 3986 section 3.2.3
allows a port of any length, but the port column is an R integer,
so under url_standard = "rfc3986" a port above 2147483647 makes
the URL a parse error on every scheme (RUL-036): a representation limit,
not a syntax verdict. It fires only where the port alone failed the row
(the twin with that port written 0 parses under the same options),
and alone, under either scheme_acceptance.
For a length-1 url, a character vector of zero or more
diagnostic tokens for that URL. For a length-n url (including
n == 0), a list of length n whose i-th element is the character
vector of that URL's tokens (character(0) when it has none).
An empty result means exactly one thing: that URL raised no
diagnostics under the selected standard. character(0) is
evidence that the URL is clean under that profile.
The diagnostics are deliberately a selected set of facts, not a complete validator. The absence of a diagnostic never implies the URL conforms to its scheme's specification or to WHATWG/RFC 3986. Full per-standard conformance validation is out of scope (ADR 0012 D5).
Three tokens are the exception, and consumers may rely on their
absence: ipv6-non-canonical and ipv6-embedded-ipv4 (each
within the scope its entry below states) and
domain-invalid-ace-label, which fires on every parsed
URL host that meets its predicate (see its entry below), under both
"rfc3986" and "whatwg". Its absence means each
xn-- label of the host
is, on its own, a genuine A-label. It says nothing about the host's other
labels or about the DNS rules the other domain-* tokens report.
Credentials and host facts describe a URL authority, so they are
reported only where the parse produced one with a host. A URL whose parse
has none (a WHATWG opaque path such as mailto:[email protected]; an RFC 3986
path-rootless or path-absolute path, with no authority)
reports none of them: a mailto: recipient's domain is not a URL
host. get_mailto_recipients judges recipients.
Two WHATWG-generic facts gate on the interpreting standard, not the
acceptance axis, so they are reported whenever url_standard =
"whatwg" — including the default "web" acceptance path (they are
route-independent, string-level facts; RURL-sgjzbqzk):
invalid-URL-unit / invalid-credentials — WHATWG
validation errors (WHATWG-verbatim names): a malformed %-escape
or a non-URL code point, and credentials (userinfo) in a parsed
authority. Bounded detection.
The default combination ("web" acceptance with url_standard =
NULL) emits no diagnostics at all, so it is unaffected.
With scheme_acceptance = "general" (the general-parser posture) a
further set of selected facts is reported. These fire only under
"general"; the default "web" acceptance never emits them:
transform-skipped-ineligible-scheme — the scheme is
non-HTTP(S) and so ineligible for the SEO/semantic Stage-B transforms.
scheme-specific facts: ws-fragment-forbidden /
ws-userinfo-forbidden (RFC 6455),
mailto-fragment-discouraged (RFC 6068),
tel-missing-phone-context (RFC 3966),
data-missing-comma (RFC 2397), and, under "rfc3986",
file-non-absolute-path,
file-userinfo-extension (userinfo, permitted by RFC 8089
Appendix E.1's non-normative extended grammar), and
file-component-outside-rfc8089 (a port, query or fragment,
which RFC 8089's grammar does not mention and which are therefore
inherited generic RFC 3986 components).
This section is the
single authoritative enumeration of the diagnostics vocabulary.
It is held to the runtime registry (.URL_DIAGNOSTICS) in both
directions by tools/diagnostics-doc-consistency.R, a CI gate: a
token cannot be added, renamed, or removed without this list moving with
it. Earlier design documents (including the v1 selector PRD's section 7
table) are historical records of what the vocabulary was when they were
accepted — they are not registries and do not track it.
Every token below is emitted only when url_standard is not
NULL. Tokens marked general additionally require
scheme_acceptance = "general"; the rest fire under both acceptance
postures and, unless noted, under both "rfc3986" and
"whatwg".
Host — IPv4 shape. Facts about a host written as, or coerced to, an IPv4 address; security filters typically reject all of them.
ipv4-number-form — numeric IPv4 shorthand instead of
dotted decimal.
ipv4-non-dotted — a whole-host number parsed/coerced to
IPv4 in WHATWG mode.
ipv4-short-form — fewer than four dotted parts.
ipv4-non-decimal — hex or octal notation participated in
IPv4 parsing.
ipv4-octal — octal interpretation changed the apparent
address value.
ipv4-leading-zero — a dotted decimal-looking part had a
leading zero.
ipv4-out-of-range — a dotted part exceeds 255 (fatal
under "whatwg"; flags a numeric-looking reg-name under
"rfc3986", e.g. 256.1.1.1).
Host — IPv6 shape. Facts about an IPv6 literal host, keyed to
the literal as written and identical under both standards. Both are
complete for every literal the standard parses: each fires on
every such host its definition covers, so its absence can be relied on.
Only a host classified as "ipv6" (see get_host_type)
reports them: a zone ID is a parse failure under both standards, and an
IPvFuture literal is never an IPv6 host.
ipv6-non-canonical — the literal is not the WHATWG URL
Standard's IPv6 serialization of its address: leading zeros, an
uncompressed or wrongly chosen zero run, uppercase hex digits, or a
dotted IPv4 tail ([0:00::0:1], [::ffff:127.0.0.1]).
That serialization follows RFC 5952 section 4 but never uses the
section 5 mixed notation, so a literal written the way section 5
recommends still fires it.
ipv6-embedded-ipv4 — the address carries an IPv4
address under one of the embeddings raddr::addr_embedded_kind()
recognizes: IPv4-mapped, IPv4-compatible, IPv4-translated, the NAT64
well-known and local-use prefixes, 6to4, Teredo and ISATAP
([::ffff:7f00:1], [64:ff9b::7f00:1]). Use
raddr::addr_embeddings() for the kind and the IPv4 address.
Absence means raddr recognizes no embedding, not that the address
cannot reach IPv4: a network-specific NAT64 prefix (RFC 6052 section
2.2) is not visible from the address alone. A caller who knows its
prefix can test for it with raddr::addr_nat64_embeddings().
An empty result is no evidence that an IPv6 host is safe to fetch:
[::1] carries neither token. Judging the destination address is
the caller's policy, not a diagnostic.
Host — DNS length, UTS-46 and charset. Probed against the resolved host; IP literals are excluded.
domain-label-too-long — a label exceeds the DNS 63-byte
limit.
domain-name-too-long — the whole name exceeds the DNS
253-byte limit.
domain-empty-label — the host contains an empty label
(a ".." run, or a leading dot).
domain-hyphen-violation — a label breaks the UTS-46
hyphen rules (leading/trailing hyphen, or "--" in positions
3–4 of a non-xn-- label).
domain-std3-violation — a label carries a code point
outside the STD3 LDH set.
domain-invalid-ace-label — a label beginning
xn-- (in any ASCII case) is not a genuine A-label: its Punycode
decode fails (including an empty or all-ASCII result), or the decoded
label fails the UTS #46 Validity Criteria (section 4.1) under the
WHATWG URL Standard's non-strict flags (CheckHyphens,
UseSTD3ASCIIRules and VerifyDnsLength false;
CheckBidi and CheckJoiners true). Each such label is
judged on its own, so criterion 9 applies as though the label were
the whole name: a label that is valid alone but fails the Bidi rule
only because another label makes the name a Bidi domain name does not
fire it. The host still
parses: under "whatwg" the domain parser keeps an ASCII host
whose ToASCII fails, lowercased. Unlike the rest of this vocabulary,
this token is complete: it fires on every host meeting the
predicate, so its absence can be relied on. It can co-fire with
domain-hyphen-violation (a decoded label beginning
xn-- breaks both the strict and the non-strict hyphen rule),
and with domain-empty-label when another label is empty. Hyphen,
STD3 and length facts alone never fire it. Where it fires, those three
facts can be missing: they are computed only for a host whose relaxed
UTS #46 processing succeeds as a whole.
host-charset-shimmed — the host carries one of the 15
code points WHATWG keeps but the historical parser rejected,
accepted by the shim (ADR 0009: ! $ & ( ) * + , ; =, plus the
ASCII quotation mark, apostrophe, grave accent, and the two braces).
"whatwg" only.
Path.
encoded-dot-segment — an encoded-dot segment
(%2e / %2e%2e, any hex case) that the profile's dot
handling acted on.
encoded-reserved-path-byte — the preserved path still
carries an encoded reserved byte (%2F, %3F,
%23) held as data rather than as a separator.
Port. Facts about the raw port versus the resolved scheme's
WHATWG default, independent of the port_handling knob.
explicit-default-port — the port was written out and
equals the scheme's default.
non-default-port — a port is present and is not the
scheme's default (including any port on a scheme with no defined
default).
port-out-of-integer-range — the rejection reason for a
URL that failed under "rfc3986" only because its port is
above 2147483647, the largest R integer (RUL-036). Both acceptance
postures; "rfc3986" only. See the description above.
Input shape — WHATWG cleanup. All three are "whatwg"
only; "rfc3986" has no strip or rewrite step.
invalid-reverse-solidus — a literal \ was
reinterpreted as / (special schemes only).
control-char-stripped — an ASCII tab/LF/CR was removed
from the interior of the input (step 1, second half).
leading-trailing-stripped — a leading and/or trailing run
of C0-control-or-SPACE was removed (step 1, first half).
Layer 5 — selected per-standard and per-scheme facts (ADR 0012 D5). Described in full under Selected facts, not a conformance oracle above.
invalid-URL-unit — WHATWG validation error: a malformed
%-escape or a non-URL code point. "whatwg" only.
invalid-credentials — WHATWG validation error:
credentials (userinfo) are present. "whatwg" only.
unicode-outside-rfc3986-uri — the rejection reason for
a URL that failed under "rfc3986" because it carries a
directly written non-ASCII character (RFC 3986 sections 2, 2.5 and
3.2.2) and whose percent-encoded twin parses. Both acceptance
postures; "rfc3986" only. See the description above.
transform-skipped-ineligible-scheme — general;
a non-HTTP(S) scheme, ineligible for the Stage-B transforms.
ws-fragment-forbidden — general; a fragment on a
ws:/wss: URL (RFC 6455).
ws-userinfo-forbidden — general; userinfo on a
ws:/wss: URL (RFC 6455).
mailto-fragment-discouraged — general; a fragment
on a mailto: URL (RFC 6068).
tel-missing-phone-context — general; a local
tel: number with no phone-context (RFC 3966).
data-missing-comma — general; a data: URL
with no "," separator (RFC 2397).
file-non-absolute-path — general; a
non-absolute file: path under "rfc3986".
file-userinfo-extension — general; userinfo on a
file: URL, permitted by RFC 8089 Appendix E.1's non-normative
extended grammar.
file-component-outside-rfc8089 — general; a port,
query or fragment on a file: URL, inherited from generic
RFC 3986.
get_url_diagnostics("http://example.com/", url_standard = "rfc3986") get_url_diagnostics( c("http://example.com/", "http://2130706433/"), url_standard = "whatwg" )get_url_diagnostics("http://example.com/", url_standard = "rfc3986") get_url_diagnostics( c("http://example.com/", "http://2130706433/"), url_standard = "whatwg" )
Projects each URL onto a versioned, non-URL comparison key: the value rurl uses to decide whether two URLs identify the same web resource. Use it to deduplicate, group, or match URLs without relying on a cleaned display string.
get_url_key(url, policy = url_key_policy())get_url_key(url, policy = url_key_policy())
url |
A character vector of URLs. Factors are coerced. |
policy |
A |
A classed character vector (rurl_url_key) the same length as
url, preserving its names. NA for a non-keyable element. The policy
version, schema version, standard, scheme-equality mode and the per-element
keyability reasons ride along as attributes.
The returned object is a classed character vector whose contents are
injectively framed component bytes, not a URL. Never parse it, never render
it to users, and never reconstruct a URL from it. print() deliberately
shows a truncated diagnostic form for that reason. What it is good for is
comparison: ==, match(), duplicated(), %in% and the url_join
family all work on it directly.
Framing is length-prefixed, so component boundaries cannot be forged. A host or path containing separators, control bytes or colons can never make two different URLs collide.
A URL the selected standard cannot parse has no identity, so its key is
NA and never matches anything – not even another NA. The reason is kept
alongside rather than collapsed into the NA, and is readable with
attr(key, "keyability"): one of "ok", "missing-input", "empty-input"
or "invalid-parse". Missing input is never conflated with an invalid
parse.
url_key_policy() for the dials, url_join for joining on the
key, and serialize_url() for a standard's full-string serialization
(which is a URL, unlike this).
# Presentation differences that are not identity differences. get_url_key(c("http://example.com:80/a", "http://example.com/a")) # The fragment and userinfo are excluded from web-resource identity. k <- get_url_key(c("http://u:[email protected]/a#top", "http://example.com/a")) k[1] == k[2] # Query order and duplicates are significant. k <- get_url_key(c("http://example.com/?a=1&b=2", "http://example.com/?b=2&a=1")) k[1] == k[2] # Deduplicate by identity rather than by string. u <- c("HTTP://Example.com/a", "http://example.com/a", "http://example.com/b") u[!duplicated(get_url_key(u))] # Non-keyable input carries a typed reason. k <- get_url_key(c("http://example.com/", NA, "", ":::")) attr(k, "keyability")# Presentation differences that are not identity differences. get_url_key(c("http://example.com:80/a", "http://example.com/a")) # The fragment and userinfo are excluded from web-resource identity. k <- get_url_key(c("http://u:[email protected]/a#top", "http://example.com/a")) k[1] == k[2] # Query order and duplicates are significant. k <- get_url_key(c("http://example.com/?a=1&b=2", "http://example.com/?b=2&a=1")) k[1] == k[2] # Deduplicate by identity rather than by string. u <- c("HTTP://Example.com/a", "http://example.com/a", "http://example.com/b") u[!duplicated(get_url_key(u))] # Non-keyable input carries a typed reason. k <- get_url_key(c("http://example.com/", NA, "", ":::")) attr(k, "keyability")
Extracts the user component of a URL. The value is not percent-decoded.
Under url_standard = "whatwg" it carries the standard's
percent-encoded spelling (WHATWG stores the username buffer encoded with the
userinfo percent-encode set, so "http://a^b@host/" yields
"a%5Eb"); under url_standard = "rfc3986" it is the raw source
spelling, exactly as written in the URL.
get_user( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_user( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A URL with no authority gives NA. That includes a mailto: URL
such as mailto:[email protected]: it is an opaque path (WHATWG URL
Standard; RFC 3986 section 3) and carries no userinfo, as
safe_parse_url's user column says. Read a recipient's
local-part with get_mailto_recipients.
A character vector of user names.
get_mailto_recipients for the full per-recipient list.
get_user("ftp://user:[email protected]/file.txt") get_user("mailto:[email protected]", scheme_acceptance = "general", url_standard = "rfc3986") # NA: no authorityget_user("ftp://user:[email protected]/file.txt") get_user("mailto:[email protected]", scheme_acceptance = "general", url_standard = "rfc3986") # NA: no authority
Extracts the userinfo component of a URL (user or user:password).
get_userinfo( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )get_userinfo( url, protocol_handling = "keep", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg" )
url |
A character vector of URLs. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
A character vector of userinfo values.
get_userinfo("ftp://user:[email protected]/file.txt") get_userinfo("ftp://[email protected]/file.txt")get_userinfo("ftp://user:[email protected]/file.txt") get_userinfo("ftp://[email protected]/file.txt")
A policy predicate layered on top of standards-correct parsing. rurl's
url_standard profiles deliberately match the URL standards
rather than impose practical web/SEO hygiene, so hosts such as
a+b.example (a valid RFC 3986 reg-name), _dmarc.example.com (a
valid DNS owner name), or -example.com all parse successfully.
is_valid_host() answers the separate, product-level question of
whether such a host is usable as a practical web hostname, DNS owner name,
registrable site host, or SEO-safe host.
is_valid_host( url, rule = c("web", "dns", "registrable", "seo", "url"), url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )is_valid_host( url, rule = c("web", "dns", "registrable", "seo", "url"), url_standard = "whatwg", scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general") )
url |
A character vector of URLs. |
rule |
A single rule to test. One of:
|
url_standard |
Standard profile governing host interpretation:
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
A logical vector the same length as url. NA for a URL
with no host to judge (a host-less scheme, or an input that did not parse).
This never changes how a URL
parses: it does not turn a hostname-policy failure into a parse error, does
not affect get_parse_status, and adds no columns to
safe_parse_url. It is also not a conformance oracle
(see get_url_diagnostics and ADR 0012): a TRUE verdict
means only that rurl found no practical footgun it checks for, never that
the host is provably valid per every specification.
check_hosts for a tabular report over several rules at
once, get_host_type, get_url_diagnostics.
is_valid_host(c("http://example.com", "http://_dmarc.example.com")) # web: FALSE for the underscore host; dns: TRUE for it is_valid_host("http://_dmarc.example.com", rule = "dns") is_valid_host( c("http://a+b.example", "http://-example.com", "http://a..com"), rule = "web" ) is_valid_host( c("http://example.com", "http://localhost", "http://192.168.0.1"), rule = "registrable" )is_valid_host(c("http://example.com", "http://_dmarc.example.com")) # web: FALSE for the underscore host; dns: TRUE for it is_valid_host("http://_dmarc.example.com", rule = "dns") is_valid_host( c("http://a+b.example", "http://-example.com", "http://a..com"), rule = "web" ) is_valid_host( c("http://example.com", "http://localhost", "http://192.168.0.1"), rule = "registrable" )
Tabulates which query parameters appear across a vector of URLs and what
values they take, with a would_drop column previewing what
query_handling = "filter" would remove. Useful for auditing a URL set
before choosing a cleaning policy: see the trackers before you strip them.
query_param_summary( urls, level = c("param", "value"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE )query_param_summary( urls, level = c("param", "value"), params_keep = NULL, params_drop = NULL, params_case_sensitive = FALSE, empty_param_handling = c("keep", "drop"), decode_plus = FALSE )
urls |
A character vector of URLs. |
level |
One of "param" (default) for one row per distinct parameter name, or "value" for one row per distinct (parameter, value) pair. |
params_keep |
Character vector of parameter-name globs (only |
params_drop |
Character vector of parameter-name globs to add to the
built-in denylist in "filter" mode, or |
params_case_sensitive |
Logical (default |
empty_param_handling |
One of "keep" (default) or "drop". "drop" removes
empty-valued params (e.g. |
decode_plus |
Logical (default |
Parameter names are grouped faithfully (case-sensitively and by their
decoded spelling), so utm_source and UTM_SOURCE are reported as separate
rows. The would_drop preview, by contrast, honors params_case_sensitive:
with the default params_case_sensitive = FALSE, UTM_SOURCE matches the
built-in denylist and shows would_drop = TRUE; set it to TRUE and the
upper-case spelling no longer matches. The raw query field is only read,
never mutated.
A flat (long) data.frame. For level = "param": param, n
(total occurrences), n_urls (distinct URLs containing the param),
example_value, example_url, would_drop. For level = "value":
param, value, n, n_urls, example_url, would_drop. The
example_* columns and the param-level would_drop reflect the
first-seen occurrence (deterministic given input order). Returns a
zero-row data.frame with the level's columns when no URL carries a query.
urls <- c( "http://example.com/?utm_source=nl&id=42", "http://example.com/watch?v=abc&utm_source=x", "http://example.com/?id=99" ) query_param_summary(urls) query_param_summary(urls, level = "value") # Preview a custom policy: query_param_summary(urls, params_drop = "id")urls <- c( "http://example.com/?utm_source=nl&id=42", "http://example.com/watch?v=abc&utm_source=x", "http://example.com/?id=99" ) query_param_summary(urls) query_param_summary(urls, level = "value") # Preview a custom policy: query_param_summary(urls, params_drop = "id")
Resolves a relative or absolute URL reference against a base URL following
the RFC 3986 section 5 reference-resolution algorithm, then renders the
resolved absolute URL on the output surface output selects. Under the
default output = "clean" the result is canonicalized with the same
machinery as safe_parse_url; under output = "serialized"
it is handed to serialize_url instead. url_standard and
any ... options flow straight through to the parse, so the host
IPv4/reg-name model, path percent/dot-segment handling, default-port elision,
WHATWG backslash-as-slash recognition, and diagnostics are exactly those of a
direct safe_parse_url() call on the resolved URL.
resolve_url( relative_or_absolute, base_url, url_standard = "whatwg", output = c("clean", "serialized"), form = c("source", "normalized"), ... )resolve_url( relative_or_absolute, base_url, url_standard = "whatwg", output = c("clean", "serialized"), form = c("source", "normalized"), ... )
relative_or_absolute |
A character vector of URL references to resolve.
Each may be relative ( |
base_url |
A character vector of base URLs, recycled against
|
url_standard |
The standard the reference is resolved and parsed
under: |
output |
Which output surface to return: |
form |
For |
... |
Additional arguments forwarded to |
A character vector the same length as the recycled inputs, unnamed
(names are not data). Under output = "clean" each element is the
canonical clean_url of the resolved reference; under
output = "serialized" it is the standard's full-string
serialization of the resolved absolute URL. NA where resolution
cannot produce an absolute URL, where under "rfc3986" (named or
bundled by a profile) the
reference is no RFC 3986 URI-reference, or where the resolved URL is not
accepted by the parser ("clean") or by the selected standard's
parser ("serialized").
The merge itself (empty reference, fragment-only, query-only, scheme-relative
//host reference, absolute-path reference, and relative-path merge) is
RFC 3986 section 5.2–5.3 under url_standard = "rfc3986", with one
exception noted last below. Under url_standard = "whatwg" (the
default; NULL means the same, ADR 0020) the WHATWG
URL Standard's reference-parsing rules are applied first, because they are
rules the two standards genuinely disagree on rather than composition of the
axes url_standard already governs (decision P2.7 D-B,
design/work/url-v3/decisions/P2.7-display-and-resolver-output.md):
A reference carrying the base's own special scheme is
relative, not absolute. WHATWG's “special relative or authority
state” consumes a scheme equal to the base's when that scheme is special
(http, https, ws, wss, ftp,
file) and keeps parsing against the base, so
resolve_url("http:foo.com", "http://example.org/foo/bar",
url_standard = "whatwg") is "http://example.org/foo/foo.com",
while RFC 3986 treats any scheme as making the reference absolute and
gives "http://foo.com/". A different scheme stays absolute
under both, even when it is also special.
Under a special base, a leading \ in the reference is
a /, and a run of either introduces an authority. WHATWG's
“relative slash state” reads \ exactly as /, so
resolve_url("\x", "http://example.org/foo/bar", url_standard =
"whatwg", output = "serialized") is "http://example.org/x"; a
second slash-or-backslash enters the authority, and
“special authority ignore slashes” then skips the whole run for
the five non-file special schemes, so "///example.org/x"
and "/\/\//example.org/x" both resolve with the host
example.org. file has its own state machine and consumes
exactly two. RFC 3986 has neither rule: \ is an ordinary path
byte and // is the entire authority production.
The reference is stripped before it is read. The WHATWG
basic URL parser's step 1 removes a leading and trailing run of C0
control or SPACE (U+0000–U+0020) and then every ASCII tab, LF and CR,
so " foo.com " resolves as "foo.com" does. A reference that
strips to the empty string is the empty reference, which resolves to the
base minus its fragment. RFC 3986 has no strip step – such bytes are
required to be percent-encoded – so under "rfc3986" they stay
in the reference. The base gets the same step
under "whatwg", so " http://a/b/c " is the base
"http://a/b/c"; only this step: a base that the parser would
otherwise respell (a backslash for a slash) is not normalized first.
A base with an opaque path takes only a fragment. Under
"whatwg", a base such as "mailto:x" (a non-special scheme
with no // and no leading /) admits only a reference
that starts with #: resolve_url("#f", "mailto:x",
url_standard = "whatwg", output = "serialized") is
"mailto:x#f", and any other relative reference is NA
(the URL Standard's no scheme state).
Against a file: base, Windows drive letters follow
the WHATWG file: state machine. A reference that begins
with a drive letter empties the base path instead of shortening it, so
resolve_url("C|/foo", "file:///tmp/mock/path", url_standard =
"whatwg", output = "serialized") is "file:///C:/foo"; a rooted
reference inherits the base's drive letter ("/" against
"file:///C:/a/b" is "file:///C:/"); .. never
removes a lone drive letter (".." against "file:///C:/"
is "file:///C:/"); and C| in the first segment is
normalized to C:. A drive letter in the authority position
("//d:") is an empty host plus a path segment,
"file:///d:". RFC 3986 has no drive-letter concept, so under
"rfc3986" the plain section 5.2 merge applies.
Any other scheme-bearing reference resolves to its own
parse. The base plays no part, and the reference's path is left to the
WHATWG path state, so an opaque path keeps its dot segments
(resolve_url("foo:a/../b", "http://h/y", url_standard = "whatwg",
output = "serialized") is "foo:a/../b") and a file:
drive letter survives .. ("file:/C:/../x" gives
"file:///C:/x"). RFC 3986 section 5.2.2 removes the dot segments
of such a path, so under "rfc3986" the first is "foo:/b".
Every rule above applies under url_standard = "whatwg" (the default)
or a profile that bundles it (see ...), never under
"rfc3986" (P2.7 D-C).
Two further rules apply under both named profiles, because the two
standards agree on them. First, a resolved path whose first segment is
empty is recomposed with the /. guard: RFC 3986 section 3.3 forbids
a path beginning with // after no authority, and the WHATWG URL
serializer emits the same guard, so resolve_url("/..//path",
"non-spec:/p", url_standard = "whatwg", output = "serialized") is
"non-spec:/.//path" rather than a string that re-reads as the
authority path. Under "whatwg" a reference with a scheme of
its own reaches the parse as written, so the WHATWG serializer, not the
resolver, writes its guard: "non-spec:/..//x" gives
"non-spec:/.//x". Second, a scheme is
ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) – RFC 3986 section 3.1's
own grammar, and WHATWG's – so a relative path whose first segment merely
contains a colon is a path, not an absolute reference:
resolve_url("[61:24:74]:98", "http://example.org/foo/bar",
url_standard = "whatwg", output = "serialized") is
"http://example.org/foo/[61:24:74]:98". "rfc3986" reads no
scheme there either, but refuses the reference (see below).
Under "rfc3986" the reference must itself be an RFC 3986
URI-reference (section 4.1: a URI or a relative-ref), or the
row is NA. This is checked on the reference as written, before the
merge, so a segment that dot-segment removal would delete still counts:
resolve_url("a/\u00e4/../b", "http://b.de/", url_standard =
"rfc3986") is NA, since U+00E4 is a raw non-ASCII code point
(sections 2 and 2.5), as are "/%zz/../b" (a % that starts
no triplet) and
"10.0.0.7:8080/x" (section 4.2: a first segment holding a colon
cannot start a relative-path reference; write "./10.0.0.7:8080/x").
"whatwg" does not check the reference. Each rule in
this section applies to the standard url_standard names, or to the
one a profile in ... bundles.
output selects between two different products, not two settings of
one (decision P2.7 D-A,
design/work/url-v3/decisions/P2.7-display-and-resolver-output.md):
output = "clean" (the default) returns the canonical
clean_url of the resolved reference, not a verbatim RFC 3986
recomposition: as everywhere else in rurl, the fragment and userinfo are
excluded from clean_url, the query is included only when
query_handling != "drop" (the default drops it), and the port only
when port_handling != "exclude". This surface is
intentionally lossy – it is a cleaning/SEO product driven by
presentation policy, and it therefore cannot carry a conformance
claim. This differs from a generic resolver such as
xml2::url_absolute() or Python's urljoin, which preserve
every component verbatim; resolve_url() resolves and
canonicalizes.
output = "serialized" returns
serialize_url(<resolved absolute URL>, standard =
url_standard, form = form): the standard's own full-string
serialization, with the fragment preserved and credentials
reconstructed. This is the standards surface – the one a conformance
claim may be measured on – and it is where RFC 3986 section 5.4's own
expectations are reproduced exactly (resolve_url("?y",
"http://a/b/c/d;p?q", url_standard = "rfc3986", output = "serialized")
is "http://a/b/c/d;p?y").
output = "serialized" serializes to url_standard, which is
"whatwg" by default (and for NULL). Because
serialize_url accepts no presentation
options at all, output = "serialized" also rejects any ...
argument: honoring, say, port_handling = "exclude" is impossible on
that surface, and accepting-then-discarding it would misreport what was
returned.
To inspect individual resolved components (including the fragment), resolve
first and pass the result to safe_parse_url.
safe_parse_url, get_clean_url,
serialize_url
resolve_url("../g", "http://a/b/c/d;p?q") # -> "http://a/b/g" resolve_url("g", "http://a/b/c/d;p?q") # -> "http://a/b/c/g" resolve_url("//example.org/p", "http://a/b/c") # -> "http://example.org/p" resolve_url("https://x.com/y", "http://a/b/c") # absolute ref, base unused resolve_url(c("g", "../h"), "http://a/b/c/") # vectorized # The standards surface keeps the query and the fragment RFC 3986 section # 5.4 requires; the (lossy) clean surface drops both by design. resolve_url("?y", "http://a/b/c/d;p?q", url_standard = "rfc3986", output = "serialized") resolve_url("#s", "http://a/b/c/d;p?q", url_standard = "whatwg", output = "serialized") resolve_url("#s", "http://a/b/c/d;p?q")resolve_url("../g", "http://a/b/c/d;p?q") # -> "http://a/b/g" resolve_url("g", "http://a/b/c/d;p?q") # -> "http://a/b/c/g" resolve_url("//example.org/p", "http://a/b/c") # -> "http://example.org/p" resolve_url("https://x.com/y", "http://a/b/c") # absolute ref, base unused resolve_url(c("g", "../h"), "http://a/b/c/") # vectorized # The standards surface keeps the query and the fragment RFC 3986 section # 5.4 requires; the (lossy) clean surface drops both by design. resolve_url("?y", "http://a/b/c/d;p?q", url_standard = "rfc3986", output = "serialized") resolve_url("#s", "http://a/b/c/d;p?q", url_standard = "whatwg", output = "serialized") resolve_url("#s", "http://a/b/c/d;p?q")
Enables or disables individual caches and sets an optional bound on the
full_parse cache. Called with no arguments, it leaves the
configuration unchanged and returns the current state.
rurl_cache_config( full_parse = NULL, puny_encode = NULL, puny_decode = NULL, max_full_parse = NULL )rurl_cache_config( full_parse = NULL, puny_encode = NULL, puny_decode = NULL, max_full_parse = NULL )
full_parse |
Logical; enable/disable the full URL parse cache. |
puny_encode |
Logical; enable/disable the IDNA/Punycode encode cache. |
puny_decode |
Logical; enable/disable the Punycode decode cache. |
max_full_parse |
A single number ( |
Disabling a cache stops new writes to it (existing entries are left in
place until rurl_clear_caches is called). When
full_parse reaches max_full_parse entries, the entire
cache is cleared before the next new entry is stored, so its peak size never
exceeds the bound. This is a hard reset-watermark, not an LRU or FIFO
eviction policy: max_full_parse caps peak memory, but is not a
working-set size — once the bound is hit the cache empties completely and
rebuilds from scratch. The default bound is 100000 unique url ×
core-option combinations (the cache stores the option-independent parse core,
keyed by url, protocol/scheme handling, www_handling, and
tld_source; set max_full_parse = Inf for the historical
unbounded behavior). The
puny_encode and puny_decode caches are unbounded by design
(each stays small — bounded by the number of unique hosts/labels seen, not
URL+option combinations).
Invisibly, the updated rurl_cache_info data.frame.
rurl_cache_info, rurl_clear_caches
rurl_cache_config(max_full_parse = 10000) rurl_cache_config(puny_encode = FALSE) rurl_cache_config() # inspect current configurationrurl_cache_config(max_full_parse = 10000) rurl_cache_config(puny_encode = FALSE) rurl_cache_config() # inspect current configuration
Reports the number of entries currently held in each memoization cache, along with whether the cache is enabled and any configured entry bound.
rurl_cache_info()rurl_cache_info()
A data.frame with one row per cache (full_parse,
puny_encode, puny_decode) and columns entries,
enabled, and max_entries.
rurl_cache_config, rurl_clear_caches
get_domain("https://www.example.com") rurl_cache_info()get_domain("https://www.example.com") rurl_cache_info()
Clears the memoization caches used by rurl functions. This is useful if you need to free memory.
rurl_clear_caches()rurl_clear_caches()
Invisibly returns NULL.
rurl_clear_caches()rurl_clear_caches()
Vectorized wrapper around safe_parse_url that returns a
data.frame with one row per input URL.
safe_parse_urls( url, protocol_handling = c("keep", "none", "strip", "http", "https"), www_handling = c("none", "strip", "keep", "if_no_subdomain"), tld_source = c("all", "private", "icann"), case_handling = c("lower_host", "keep", "lower", "upper"), trailing_slash_handling = c("none", "keep", "strip"), index_page_handling = c("keep", "strip"), path_normalization = c("none", "collapse_slashes", "dot_segments", "both"), scheme_relative_handling = c("keep", "http", "https", "error"), subdomain_levels_to_keep = NULL, host_encoding = c("keep", "idna", "unicode"), path_encoding = c("keep", "encode", "decode"), query_handling = c("drop", "filter", "allow", "keep"), params_keep = NULL, params_drop = NULL, sort_params = FALSE, empty_param_handling = c("keep", "drop"), params_case_sensitive = FALSE, decode_plus = FALSE, port_handling = c("exclude", "keep", "strip_default", "strip_all"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL, profile = NULL, credential_handling = c("strip", "reject"), path_normalisation = NULL )safe_parse_urls( url, protocol_handling = c("keep", "none", "strip", "http", "https"), www_handling = c("none", "strip", "keep", "if_no_subdomain"), tld_source = c("all", "private", "icann"), case_handling = c("lower_host", "keep", "lower", "upper"), trailing_slash_handling = c("none", "keep", "strip"), index_page_handling = c("keep", "strip"), path_normalization = c("none", "collapse_slashes", "dot_segments", "both"), scheme_relative_handling = c("keep", "http", "https", "error"), subdomain_levels_to_keep = NULL, host_encoding = c("keep", "idna", "unicode"), path_encoding = c("keep", "encode", "decode"), query_handling = c("drop", "filter", "allow", "keep"), params_keep = NULL, params_drop = NULL, sort_params = FALSE, empty_param_handling = c("keep", "drop"), params_case_sensitive = FALSE, decode_plus = FALSE, port_handling = c("exclude", "keep", "strip_default", "strip_all"), scheme_policy = c("infer", "require"), scheme_acceptance = c("web", "general"), url_standard = "whatwg", engine = NULL, profile = NULL, credential_handling = c("strip", "reject"), path_normalisation = NULL )
url |
A character vector of URLs to be parsed. |
protocol_handling |
A character string specifying how the scheme is
presented in
|
www_handling |
A character string specifying how to handle "www"
and
|
tld_source |
Which TLD source to use for TLD extraction: "all", "icann", or "private". Defaults to "all". |
case_handling |
A character string specifying how to handle the case of the cleaned URL. Defaults to "lower_host", the RFC 3986 §6.2.2.1 normalization (scheme and host are case-insensitive and folded to lowercase; the path is case-sensitive and preserved).
|
trailing_slash_handling |
A character string specifying how to handle
trailing slashes in the path of
|
index_page_handling |
A character string specifying how to handle
index/default pages in
|
path_normalization, path_normalisation
|
How to normalize path
structure. Defaults to "none".
|
scheme_relative_handling |
How to handle URLs starting with "//". Defaults to "keep".
|
subdomain_levels_to_keep |
An integer or NULL. Determines how many
levels of subdomains are kept,
in addition to any 'www.' prefix handled by
|
host_encoding |
How to present the host in
Under
|
path_encoding |
How to present the path percent-encoding in
|
query_handling |
A character string controlling whether (and how) the
query string is included in
In every non-"drop" mode the surviving query is re-encoded canonically
(uppercase percent-hex, spaces as |
params_keep |
Character vector of parameter-name globs (only |
params_drop |
Character vector of parameter-name globs to add to the
built-in denylist in "filter" mode, or |
sort_params |
Logical (default |
empty_param_handling |
One of "keep" (default) or "drop". "drop" removes
empty-valued params (e.g. |
params_case_sensitive |
Logical (default |
decode_plus |
Logical (default |
port_handling |
A character string controlling whether the port
appears in
|
scheme_policy |
Controls whether scheme-less, host-shaped input is
accepted (an input-acceptance axis, distinct from
|
scheme_acceptance |
Which scheme tokens may enter parsing (a
scheme-acceptance axis, distinct from
Note that |
url_standard |
The standard the URL is parsed under: |
engine |
Optional pslr engine controlling which Public Suffix List
backs domain / TLD / subdomain extraction: |
profile |
Optional named profile bundling several knobs at once: |
credential_handling |
How
There is no "keep": |
A data.frame with one row per URL and the same fields returned by
safe_parse_url. Invalid inputs return NA fields with
parse_status = "error". Names on url are not carried into the
result: the frame always has ordinary sequential row names, matching the
accessors (get_host and friends), which return unnamed
vectors.
safe_parse_urls(c("example.com", "https://www.example.com/path"))safe_parse_urls(c("example.com", "https://www.example.com/path"))
Renders each URL as the selected standard would serialize it: the
full string, credentials and fragment included, with a present-but-empty
? or # delimiter preserved. This is rurl's standard serialization
surface, and it is deliberately not get_clean_url().
serialize_url( url, standard = c("whatwg", "rfc3986"), form = c("source", "normalized"), engine = NULL ) serialise_url( url, standard = c("whatwg", "rfc3986"), form = c("source", "normalized"), engine = NULL )serialize_url( url, standard = c("whatwg", "rfc3986"), form = c("source", "normalized"), engine = NULL ) serialise_url( url, standard = c("whatwg", "rfc3986"), form = c("source", "normalized"), engine = NULL )
url |
A character vector of URLs. |
standard |
The standard to serialize to: |
form |
For |
engine |
Optional |
serialise_url() is the British-spelling alias of
serialize_url(): the same function under a second name.
A character vector the same length as url. NA_character_ for
input the selected standard's parser does not accept, and for input with
no scheme, a //host network-path reference included (see "Parse
posture").
serialize_url() answers "what does this URL look like under the URL
Standard / RFC 3986?". get_clean_url() answers "what is the canonical,
tidied form of this URL for SEO or deduplication?". They are different
products, not two settings of one:
serialize_url() preserves userinfo, the fragment, and empty delimiters;
takes no presentation options; and is the substrate rurl's conformance
claims are measured on.
get_clean_url() drops userinfo and the fragment by design, and is driven
by cleaning policy (www_handling, trailing_slash_handling,
index_page_handling, query filtering, port handling, and so on).
Because a standard serialization is an identity, serialize_url() accepts
no presentation arguments at all. There is no port_handling,
trailing_slash_handling or path_encoding to pass; asking a serializer to
strip a trailing slash would be a category error.
Each standard is parsed under its own spec posture – the "whatwg" and
"rfc-syntax" profiles (see url_profile()). Both accept any scheme, and
both require a scheme: neither standard defines a base-URL-free parse of
example.com/x, so scheme-less input returns NA rather than being silently
upgraded to https://. That includes a //host network-path reference such
as //example.com/x: it is a relative reference (RFC 3986 section 4.2), not
a URI, so it returns NA even where the "rfc-syntax" parse accepts it.
Input that the standard's parser rejects also returns NA.
standard = "whatwg"The WHATWG URL Standard's URL serializer
(#concept-url-serializer). Spec-exact, which makes credentials lossy in
one direction: WHATWG appends credentials only when the username or
password is non-empty, so http://@h/ serializes as http://h/ and
http://u:@h/ as http://u@h/. Both are pinned by the Web Platform
Tests. form is ignored.
standard = "rfc3986", form = "source"RFC 3986 section 5.3
component recomposition with no normalization: source bytes are
preserved and the undivided userinfo slice is emitted verbatim (RFC
3986 has no username/password split), so every credential spelling u@,
u:@, :p@, @ – survives.
standard = "rfc3986", form = "normalized"Adds RFC 3986 section
6.2.2 syntax-based normalization (scheme and host case, percent-encoding
triplet case and unreserved-octet decoding, dot-segment removal) and the
section 6.2.3 default-port elision. Dot segments are removed from a path
without a leading / too (foo:a/../b becomes foo:/b), as section
5.2.2 does for any reference with a scheme; the result is equivalent
in the generic syntax, which a scheme's own rules may not share. A path
with no authority keeps its dot segments where removing them would
leave it starting with //,
which section 3.3 forbids (foo:/a/..//p stays as written rather than
becoming foo://p, a URI with the host p).
Both RFC forms are exposed because choosing one would forfeit either the
round-trip oracle (source) or the normalized comparison substrate
(normalized).
get_clean_url() for the cleaning surface, safe_parse_url() for
the parsed components, and url_profile() for the parse postures used
here.
# The fragment and credentials survive; clean_url drops both by design. serialize_url("http://user:[email protected]:80/a/../b?q=1#frag") get_clean_url("http://user:[email protected]:80/a/../b?q=1#frag") # A present-but-empty delimiter carries information and is preserved. serialize_url(c("http://example.com/", "http://example.com/#", "http://example.com/?")) # RFC 3986: source-preserving versus normalized. serialize_url("HTTP://Example.COM:80/a/%7Euser/../x", standard = "rfc3986") serialize_url("HTTP://Example.COM:80/a/%7Euser/../x", standard = "rfc3986", form = "normalized") # Any scheme is accepted; no scheme is not. serialize_url(c("urn:ietf:rfc:2648", "mailto:[email protected]", "foo://h/x")) serialize_url("example.com/x")# The fragment and credentials survive; clean_url drops both by design. serialize_url("http://user:[email protected]:80/a/../b?q=1#frag") get_clean_url("http://user:[email protected]:80/a/../b?q=1#frag") # A present-but-empty delimiter carries information and is preserved. serialize_url(c("http://example.com/", "http://example.com/#", "http://example.com/?")) # RFC 3986: source-preserving versus normalized. serialize_url("HTTP://Example.COM:80/a/%7Euser/../x", standard = "rfc3986") serialize_url("HTTP://Example.COM:80/a/%7Euser/../x", standard = "rfc3986", form = "normalized") # Any scheme is accepted; no scheme is not. serialize_url(c("urn:ietf:rfc:2648", "mailto:[email protected]", "foo://h/x")) serialize_url("example.com/x")
Six joins that match rows on URL identity rather than on string equality.
Each side names one URL column; both sides are keyed with one immutable
url_key_policy(), and rows pair up when their comparison keys are equal.
url_inner_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_left_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_right_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_full_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_semi_join( x, y, by, policy = url_key_policy(), key_name = NULL, relationship = "none", invalid = "keep", warnings = "allow", engine = NULL ) url_anti_join( x, y, by, policy = url_key_policy(), key_name = NULL, relationship = "none", invalid = "keep", warnings = "allow", engine = NULL )url_inner_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_left_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_right_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_full_join( x, y, by, policy = url_key_policy(), suffix = c(".x", ".y"), key_name = NULL, relationship = "none", multiple = "all", invalid = "keep", warnings = "allow", engine = NULL ) url_semi_join( x, y, by, policy = url_key_policy(), key_name = NULL, relationship = "none", invalid = "keep", warnings = "allow", engine = NULL ) url_anti_join( x, y, by, policy = url_key_policy(), key_name = NULL, relationship = "none", invalid = "keep", warnings = "allow", engine = NULL )
x, y
|
Data frames to join. |
by |
The URL columns to key on: either one column name present on both
sides ( |
policy |
A |
suffix |
Length-2 character vector disambiguating column names present
on both sides. Default |
key_name |
Optional column name under which to expose the comparison
key. |
relationship |
Cardinality you assert about matching keys, checked
before the result is materialized: |
multiple |
How many |
invalid |
What to do with rows that cannot be keyed: |
warnings |
What to do with rows that parsed with a warning: |
engine |
Optional |
A data frame built by row-slicing x, so x's column types and
subclass survive. url_inner_join(), url_left_join(),
url_right_join() and url_full_join() return x's columns followed by
y's, disambiguated by suffix; url_semi_join() and url_anti_join()
return x's columns only. A zero-row result is built by the same path, so
it carries the complete typed schema.
Joining data frames on raw URL strings misses http://example.com:80/a
against http://example.com/a. Joining them on a cleaned string
overmatches instead, because cleaning is a display policy: it can strip a
trailing slash, a query parameter or a www. that genuinely distinguished
two resources. These joins use get_url_key(), so what matches is what rurl
considers the same resource – and no cleaning or display option can change
that.
Order is part of the contract, not an artifact of the implementation:
url_inner_joinmatching pairs in x order, y matches in y
order within each x row.
url_left_joinevery x row in x order; unmatched x rows carry
a missing y payload typed from y's own columns.
url_right_jointhe exact mirror: every y row in y order, x
matches in x order.
url_full_jointhe left-join result, then the y rows it never
consumed, in y order.
url_semi_joineach x row with at least one match, once, x
columns only.
url_anti_joineach x row with no match, once, x columns only.
Duplicate keys expand as a Cartesian product. Rows are never silently
discarded to "resolve" a duplicate – multiplicity is a fact you declare with
relationship or narrow with multiple.
A URL the standard cannot parse, or a missing or empty one, has no identity
and never matches – not even another unparseable URL. invalid decides what
happens to those rows: "keep" (default) leaves them in, unmatched, so a
left join still returns them; "drop" removes them before matching;
"error" refuses the join and reports the offending row positions.
warnings is a separate axis for rows that did parse but carry a note –
userinfo on a scheme-less input, or a host whose public-suffix annotation did
not resolve. "allow" (default) matches them normally, "reject" makes them
ineligible to match without removing them, and "error" refuses the join.
url_anti_join() keeps non-keyable x rows, because a row that cannot match
anything is exactly what an anti join asks for.
Failures raise typed conditions – rurl_url_join_input_error,
rurl_url_join_policy_error, rurl_url_join_suffix_error,
rurl_url_join_key_name_error, rurl_url_join_relationship_error,
rurl_url_join_invalid_error and rurl_url_join_warning_error, all
inheriting from rurl_url_join_error – so they can be caught precisely.
Messages report row positions and truncated keys, never URL content, so a
credential in the input cannot leak into an error message.
get_url_key() and url_key_policy() for the identity model, and
canonical_join(), deprecated and removed in rurl 4.0.0, for the legacy
join that matches on cleaned strings.
pages <- data.frame( URL = c("http://example.com:80/a", "https://example.com/b", "http://example.com/c?", "not a url"), clicks = c(10, 20, 30, 40), stringsAsFactors = FALSE ) meta <- data.frame( URL = c("http://example.com/a", "http://example.com/b", "http://example.com/c"), title = c("A", "B", "C"), stringsAsFactors = FALSE ) # Only row 1 matches: `:80` is redundant under http, but http is not https, # and a present-but-empty query is not the same resource as no query. url_inner_join(pages, meta, by = "URL") # Every left row survives, unmatched ones with a typed missing payload. url_left_join(pages, meta, by = "URL") # Rows that could not be parsed at all. url_anti_join(pages, meta, by = "URL") # Expose the key you matched on. url_inner_join(pages, meta, by = "URL", key_name = "key") # Relaxing scheme equality brings row 2 in. url_inner_join(pages, meta, by = "URL", policy = url_key_policy(scheme_equality = "http_https"))pages <- data.frame( URL = c("http://example.com:80/a", "https://example.com/b", "http://example.com/c?", "not a url"), clicks = c(10, 20, 30, 40), stringsAsFactors = FALSE ) meta <- data.frame( URL = c("http://example.com/a", "http://example.com/b", "http://example.com/c"), title = c("A", "B", "C"), stringsAsFactors = FALSE ) # Only row 1 matches: `:80` is redundant under http, but http is not https, # and a present-but-empty query is not the same resource as no query. url_inner_join(pages, meta, by = "URL") # Every left row survives, unmatched ones with a typed missing payload. url_left_join(pages, meta, by = "URL") # Rows that could not be parsed at all. url_anti_join(pages, meta, by = "URL") # Expose the key you matched on. url_inner_join(pages, meta, by = "URL", key_name = "key") # Relaxing scheme equality brings row 2 in. url_inner_join(pages, meta, by = "URL", policy = url_key_policy(scheme_equality = "http_https"))
Builds the immutable, versioned policy object that governs URL identity
for get_url_key() and the url_join family. One policy is applied
symmetrically to both sides of every comparison, because equality has to
stay symmetric and transitive.
url_key_policy( standard = c("whatwg", "rfc3986"), scheme_equality = c("exact", "http_https", "http_https_missing") )url_key_policy( standard = c("whatwg", "rfc3986"), scheme_equality = c("exact", "http_https", "http_https_missing") )
standard |
The standard whose identity semantics apply: |
scheme_equality |
How strictly schemes compare. |
scheme_equality = "http_https_missing" would additionally collapse "no
scheme written" into the http/https class. It errors rather than
guessing, because the pair it would have to equate also differs on whether
an authority delimiter (//) was present, which rurl frames as independent
identity. Collapsing that too is a contract change, not an implementation
detail, so the mode refuses instead of silently picking a side.
An object of class rurl_url_key_policy.
A comparison key is derived from the URL's canonical identity state – after
the selected standard has interpreted it, and before any cleaning or
display transform. No cleaning option can reach it. www_handling,
case_handling, trailing_slash_handling, index_page_handling,
path_encoding, host_encoding, port_handling, query cleaning and every
url_profile() bundle are structurally incapable of changing a key byte.
That is the point: two URLs that a cleaning profile happens to render alike
are not thereby the same resource.
Framed as identity: the scheme (and, separately, whether one was written at all), the authority delimiter, the host and its kind, the port, the path and its kind, and the query – order and duplicates significant.
Excluded by contract: the fragment and any userinfo. Neither identifies a
web resource, so http://u:pw@h/p#frag and http://h/p mint the same key.
Their structural state is still available from safe_parse_url() and the
diagnostics helpers.
Ports normalize only where the standard makes them redundant: an explicit
:80 under http and :443 under https compare equal to no port at all.
Every other default stays literal, so ftp://h:21/ and ftp://h/ are
distinct, and an inferred scheme normalizes nothing (h.com:80/ is not
http://h.com/).
The policy carries a key version and a schema version, and both travel inside the framed key bytes. A key minted under different semantics can therefore never compare equal to one minted here, so no release can silently reinterpret a persisted key.
get_url_key() for the key itself, and url_join for the joins
that consume it.
url_key_policy() # Identity under one policy ... get_url_key(c("http://example.com/", "https://example.com/")) # ... and under a relaxed scheme mode. p <- url_key_policy(scheme_equality = "http_https") k <- get_url_key(c("http://example.com/", "https://example.com/"), p) k[1] == k[2]url_key_policy() # Identity under one policy ... get_url_key(c("http://example.com/", "https://example.com/")) # ... and under a relaxed scheme mode. p <- url_key_policy(scheme_equality = "http_https") k <- get_url_key(c("http://example.com/", "https://example.com/"), p) k[1] == k[2]
Expands a named profile into the resolved bundle of low-level parser
knobs it sets, running the exact same resolution the parse functions
(safe_parse_url, safe_parse_urls,
get_clean_url) apply when you pass profile. It never
parses a URL; it answers “what does this profile actually do, and did
my explicit overrides change it?”.
url_profile(profile = NULL, ...)url_profile(profile = NULL, ...)
profile |
A single profile name: one of |
... |
Optional explicit knob overrides (e.g. |
Profiles are inspectable sugar that bundle the parser's acceptance,
interpretation, leniency, and canonicalization axes under one name. Explicit
arguments always override the profile (the iron rule); when any override is
supplied, the resolved result is flagged customized = TRUE and rurl no
longer claims the result matches the named profile exactly.
The recognized profiles are "browser" (browser-like
http-prepending fix-up posture that also reads input starting with a single
/ as a local file: path; not Chrome-faithful), "whatwg"
(absolute-URL, no-base spec posture that rejects scheme-less input),
"rfc-syntax" (RFC 3986 generic syntax as parsing, not
normalization: case and dot-segments are preserved), and "seo"
(rurl's origin-cleaning intent; "canonical" is an alias resolving
identically to "seo").
"seo" delivers rurl's definition of a clean URL: a
lossy policy projection of a WHATWG-parsed URL (ADR 0017), never a
separate, weaker construction. It selects url_standard = "whatwg" as
the identity underneath — which is also what resolves . and ..
folder segments — and host_encoding = "unicode", so the host is
canonical in one direction regardless of whether the input spelled it in
Unicode or Punycode. The remaining knobs are the projection: https, strip
www, trailing slash and index page, drop the whole query, and
drop a default port only (port_handling = "strip_default"):
a non-default port such as :8080 names a different origin and
survives (RFC 3986 §6.2.3; WHATWG URL Standard port state; RFC 6454 §4;
RUL-016). The
result makes no claim of resource equivalence and is not an HTML canonical
URL — forcing https, stripping www and dropping the query can each
change the resource addressed. As always, an explicit argument overrides the
bundle, so query_handling = "filter" still buys tracker-only removal.
A named list of the resolved knob value pairs the
profile sets (the same shape as an internal profile bundle), plus a
trailing logical customized element.
"seo"
The bundle applies two kinds of transform, and a reader cannot tell them
apart from the profile name alone (RUL-017). Normalization is
what a standard says yields the same resource: the WHATWG parse with its
dot-segment resolution (url_standard = "whatwg"), host case folding
and UTS #46 rendering (host_encoding = "unicode"), and removal of a
default port only (port_handling = "strip_default").
Editorial is a claim about how the site is configured that no
standard settles: forcing https (protocol_handling), folding
www. (www_handling), stripping a trailing slash
(trailing_slash_handling) and a terminal index page
(index_page_handling), and dropping the whole query
(query_handling = "drop"). Each editorial knob can change the
addressed resource, and each is in the bundle on purpose: an SEO bundle
exists to say which URL a page should be known as, which is a site policy.
Pass any knob explicitly to turn it off, and use get_url_key
when you need resource identity rather than a display string.
safe_parse_url, get_scheme_class
url_profile("browser") url_profile("seo") # canonical is an alias of seo: identical(url_profile("canonical"), url_profile("seo")) # explicit overrides win and flag the result customized: url_profile("browser", scheme_policy = "require")url_profile("browser") url_profile("seo") # canonical is an alias of seo: identical(url_profile("canonical"), url_profile("seo")) # explicit overrides win and flag the result customized: url_profile("browser", scheme_policy = "require")