Why value cannot be used as the base URL, or undefined when it can. The engine
appends every request path to the base URL as a string, so the rules guard the
request URL it builds:
it must parse as an absolute URL with an http: or https: scheme (a file: or
ftp: base URL would otherwise reach a custom transport that does no such check);
no ? or #: either would swallow every path (http://h/?x=1 requests
/?x=1/o/autobahn/..., http://h/#f requests /);
no backslash: WHATWG ends an http(s) host at one, as at a /, while text-based code reads
on, so https://u:pw@a.example\@b.example was checked as a.example and its credentials
could go to b.example;
a % in the user name or password must start a valid escape (%25 for a literal one):
Node decodes the userinfo for the Authorization header and fails at request time;
no surrounding whitespace (U+00A0 included) and no control character anywhere:
new URL() trims or drops them silently, so the URL requested would not be the one
typed ("https://h/ " read as https://h/, a tab inside a host dropped);
the scheme followed by exactly // and the host (not http:host, http:/host or
http:///host): WHATWG skips any slashes after an http(s) scheme and repairs the URL
silently, so the host requested would not be the one typed either.
The reasons never repeat the value, nor a part of it, so a credential in it cannot reach a
message: a scheme is named (Unsupported scheme "ftp:") only when the value spells one
(<scheme>://), since a scheme-less user:password@host parses with the user name as its scheme.
The engine enforces it (as Invalid option baseUrl: <reason>), and the CLI's
--base-url parser calls it.
Why
valuecannot be used as the base URL, or undefined when it can. The engine appends every request path to the base URL as a string, so the rules guard the request URL it builds:http:orhttps:scheme (afile:orftp:base URL would otherwise reach a custom transport that does no such check);?or#: either would swallow every path (http://h/?x=1requests/?x=1/o/autobahn/...,http://h/#frequests/);/, while text-based code reads on, sohttps://u:pw@a.example\@b.examplewas checked as a.example and its credentials could go to b.example;%in the user name or password must start a valid escape (%25for a literal one): Node decodes the userinfo for the Authorization header and fails at request time;new URL()trims or drops them silently, so the URL requested would not be the one typed ("https://h/ "read ashttps://h/, a tab inside a host dropped);//and the host (nothttp:host,http:/hostorhttp:///host): WHATWG skips any slashes after an http(s) scheme and repairs the URL silently, so the host requested would not be the one typed either.The reasons never repeat the value, nor a part of it, so a credential in it cannot reach a message: a scheme is named (
Unsupported scheme "ftp:") only when the value spells one (<scheme>://), since a scheme-lessuser:password@hostparses with the user name as its scheme. The engine enforces it (asInvalid option baseUrl: <reason>), and the CLI's--base-urlparser calls it.