url: revert fix url.parse() for @hostname
This reverts commit 010cb714161102de50643feb1b7aa456dba11476. Refs: https://github.com/nodejs/node/issues/42279 PR-URL: https://github.com/nodejs/node/pull/42280 Fixes: https://github.com/nodejs/node/issues/42279 Reviewed-By: Stewart X Addison <sxa@redhat.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
72e83fcea6
commit
f91950c43e
23
lib/url.js
23
lib/url.js
@ -289,29 +289,22 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
|
|||||||
rest = rest.slice(proto.length);
|
rest = rest.slice(proto.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out if it's got a host.
|
// Figure out if it's got a host
|
||||||
// user@server is *always* interpreted as a hostname, and URL
|
// user@server is *always* interpreted as a hostname, and url
|
||||||
// resolution will treat //foo/bar as host=foo,path=bar because that's
|
// resolution will treat //foo/bar as host=foo,path=bar because that's
|
||||||
// how the browser resolves relative URLs. http:@example.com is treated
|
// how the browser resolves relative URLs.
|
||||||
// the same as http://example.com.
|
|
||||||
let slashes;
|
let slashes;
|
||||||
let at;
|
|
||||||
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
|
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
|
||||||
slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
|
slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
|
||||||
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
|
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
|
||||||
at = rest.charCodeAt(0) === CHAR_AT;
|
if (slashes && !(proto && hostlessProtocol.has(lowerProto))) {
|
||||||
if (!(proto && hostlessProtocol.has(lowerProto))) {
|
rest = rest.slice(2);
|
||||||
if (slashes) {
|
this.slashes = true;
|
||||||
rest = rest.slice(2);
|
|
||||||
this.slashes = true;
|
|
||||||
} else if (at) {
|
|
||||||
rest = rest.slice(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hostlessProtocol.has(lowerProto) &&
|
if (!hostlessProtocol.has(lowerProto) &&
|
||||||
(slashes || at || (proto && !slashedProtocol.has(proto)))) {
|
(slashes || (proto && !slashedProtocol.has(proto)))) {
|
||||||
|
|
||||||
// there's a hostname.
|
// there's a hostname.
|
||||||
// the first instance of /, ?, ;, or # ends the host.
|
// the first instance of /, ?, ;, or # ends the host.
|
||||||
|
@ -975,22 +975,7 @@ const parseTests = {
|
|||||||
query: null,
|
query: null,
|
||||||
pathname: '/everybody',
|
pathname: '/everybody',
|
||||||
path: '/everybody',
|
path: '/everybody',
|
||||||
href: '//fhqwhgads@example.com/everybody#to-the-limit',
|
href: '//fhqwhgads@example.com/everybody#to-the-limit'
|
||||||
},
|
|
||||||
|
|
||||||
'http:@localhost': {
|
|
||||||
protocol: 'http:',
|
|
||||||
slashes: null,
|
|
||||||
auth: null,
|
|
||||||
host: 'localhost',
|
|
||||||
port: null,
|
|
||||||
hostname: 'localhost',
|
|
||||||
hash: null,
|
|
||||||
search: null,
|
|
||||||
query: null,
|
|
||||||
pathname: '/',
|
|
||||||
path: '/',
|
|
||||||
href: 'http://localhost/',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'\bhttp://example.com/\b': {
|
'\bhttp://example.com/\b': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user