diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2022-03-10 17:51:50 +0300 |
---|---|---|
committer | Stewart X Addison <sxa@redhat.com> | 2022-03-10 17:54:40 +0300 |
commit | 96a9e00fb38b09ba93d38a3459ec4de990bcc9f9 (patch) | |
tree | 4a7e3fcc9a9fdf3a74b6deeb65682b5faf2bee64 | |
parent | ea81c5eb118584c4e5faa951618d24d5d2af44b0 (diff) |
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>
-rw-r--r-- | lib/url.js | 23 | ||||
-rw-r--r-- | test/parallel/test-url-parse-format.js | 17 |
2 files changed, 9 insertions, 31 deletions
diff --git a/lib/url.js b/lib/url.js index 63d24bef7bf..745c7c9930d 100644 --- a/lib/url.js +++ b/lib/url.js @@ -294,29 +294,22 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { rest = rest.slice(proto.length); } - // Figure out if it's got a host. - // user@server is *always* interpreted as a hostname, and URL + // Figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url // resolution will treat //foo/bar as host=foo,path=bar because that's - // how the browser resolves relative URLs. http:@example.com is treated - // the same as http://example.com. + // how the browser resolves relative URLs. let slashes; - let at; if (slashesDenoteHost || proto || hostPattern.test(rest)) { slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH && - rest.charCodeAt(1) === CHAR_FORWARD_SLASH; - at = rest.charCodeAt(0) === CHAR_AT; - if (!(proto && hostlessProtocol.has(lowerProto))) { - if (slashes) { - rest = rest.slice(2); - this.slashes = true; - } else if (at) { - rest = rest.slice(1); - } + rest.charCodeAt(1) === CHAR_FORWARD_SLASH; + if (slashes && !(proto && hostlessProtocol.has(lowerProto))) { + rest = rest.slice(2); + this.slashes = true; } } if (!hostlessProtocol.has(lowerProto) && - (slashes || at || (proto && !slashedProtocol.has(proto)))) { + (slashes || (proto && !slashedProtocol.has(proto)))) { // there's a hostname. // the first instance of /, ?, ;, or # ends the host. diff --git a/test/parallel/test-url-parse-format.js b/test/parallel/test-url-parse-format.js index a4bb141b49b..e1cf80a2778 100644 --- a/test/parallel/test-url-parse-format.js +++ b/test/parallel/test-url-parse-format.js @@ -975,22 +975,7 @@ const parseTests = { query: null, pathname: '/everybody', path: '/everybody', - 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/', + href: '//fhqwhgads@example.com/everybody#to-the-limit' }, }; |