The rule for a configured base URL — every rule, so the CLI's --base-url
parser keeps none of its own. Checked on the value as passed, before the
trailing-slash strip, in this order:
it parses as an absolute URL (so a blank value or a stray notaurl is
refused with a message about the base URL, not an opaque "Invalid URL" that
names a request path);
its scheme is http: or https: (the default transport gates this per hop,
but a custom transport may not, so a file:/ftp: base URL never reaches one);
it has no query or fragment (request paths are appended to it as a string, so
http://h/?x=1 would request /?x=1/app/... and http://h/#f would request /);
it has 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 could be checked as one host and
its credentials sent to another;
it has no surrounding whitespace (new URL() trims silently, so the URL requested
would not be the one typed);
it holds no control character (C0, TAB included, DEL, C1): new URL() drops an
inner TAB, LF or CR silently, so /p\nX requested /pX, and an echo of the value
would carry ESC to a terminal. One a path or password needs is written
percent-encoded (%09).
a % in its userinfo starts a valid escape (%25 for a literal one): Node decodes
the userinfo into the Authorization header and would otherwise fail every request
with "URI malformed";
its scheme is followed by exactly // and the host (not http:host, http:/host or
http:///host): WHATWG skips any slashes and backslashes after an http(s) scheme and
repairs the URL silently, so the host requested would not be the one typed either.
Userinfo (https://user:pw@mirror) is allowed and sent as Basic auth. No reason
echoes the value, nor a part of it, so a credential in it never reaches an error 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 rule for a configured base URL — every rule, so the CLI's
--base-urlparser keeps none of its own. Checked on the value as passed, before the trailing-slash strip, in this order:it parses as an absolute URL (so a blank value or a stray
notaurlis refused with a message about the base URL, not an opaque "Invalid URL" that names a request path);its scheme is
http:orhttps:(the default transport gates this per hop, but a custom transport may not, so afile:/ftp:base URL never reaches one);it has no query or fragment (request paths are appended to it as a string, so
http://h/?x=1would request/?x=1/app/...andhttp://h/#fwould request/);it has no backslash: WHATWG ends an http(s) host at one, as at a
/, while text-based code reads on, sohttps://u:pw@a.example\@b.examplecould be checked as one host and its credentials sent to another;it has no surrounding whitespace (
new URL()trims silently, so the URL requested would not be the one typed);it holds no control character (C0, TAB included, DEL, C1):
new URL()drops an inner TAB, LF or CR silently, so/p\nXrequested/pX, and an echo of the value would carry ESC to a terminal. One a path or password needs is written percent-encoded (%09).a
%in its userinfo starts a valid escape (%25for a literal one): Node decodes the userinfo into the Authorization header and would otherwise fail every request with "URI malformed";its scheme is followed by exactly
//and the host (nothttp:host,http:/hostorhttp:///host): WHATWG skips any slashes and backslashes after an http(s) scheme and repairs the URL silently, so the host requested would not be the one typed either.Userinfo (
https://user:pw@mirror) is allowed and sent as Basic auth. No reason echoes the value, nor a part of it, so a credential in it never reaches an error 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.