Skip to content

Commit

Permalink
url: revert fix url.parse() for @hostname
Browse files Browse the repository at this point in the history
This reverts commit 010cb71.

Refs: #42279

PR-URL: #42280
Fixes: #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>
  • Loading branch information
aduh95 authored and sxa committed Mar 10, 2022
1 parent ea81c5e commit 96a9e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
23 changes: 8 additions & 15 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 1 addition & 16 deletions test/parallel/test-url-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
};

Expand Down

0 comments on commit 96a9e00

Please sign in to comment.