Skip to content

Commit f91950c

Browse files
authored
url: revert fix url.parse() for @hostname
This reverts commit 010cb71. Refs: #42279 PR-URL: #42280 Fixes: #42279 Reviewed-By: Stewart X Addison <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 72e83fc commit f91950c

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

lib/url.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,22 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
289289
rest = rest.slice(proto.length);
290290
}
291291

292-
// Figure out if it's got a host.
293-
// user@server is *always* interpreted as a hostname, and URL
292+
// Figure out if it's got a host
293+
// user@server is *always* interpreted as a hostname, and url
294294
// resolution will treat //foo/bar as host=foo,path=bar because that's
295-
// how the browser resolves relative URLs. http:@example.com is treated
296-
// the same as http://example.com.
295+
// how the browser resolves relative URLs.
297296
let slashes;
298-
let at;
299297
if (slashesDenoteHost || proto || hostPattern.test(rest)) {
300298
slashes = rest.charCodeAt(0) === CHAR_FORWARD_SLASH &&
301-
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
302-
at = rest.charCodeAt(0) === CHAR_AT;
303-
if (!(proto && hostlessProtocol.has(lowerProto))) {
304-
if (slashes) {
305-
rest = rest.slice(2);
306-
this.slashes = true;
307-
} else if (at) {
308-
rest = rest.slice(1);
309-
}
299+
rest.charCodeAt(1) === CHAR_FORWARD_SLASH;
300+
if (slashes && !(proto && hostlessProtocol.has(lowerProto))) {
301+
rest = rest.slice(2);
302+
this.slashes = true;
310303
}
311304
}
312305

313306
if (!hostlessProtocol.has(lowerProto) &&
314-
(slashes || at || (proto && !slashedProtocol.has(proto)))) {
307+
(slashes || (proto && !slashedProtocol.has(proto)))) {
315308

316309
// there's a hostname.
317310
// the first instance of /, ?, ;, or # ends the host.

test/parallel/test-url-parse-format.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -975,22 +975,7 @@ const parseTests = {
975975
query: null,
976976
pathname: '/everybody',
977977
path: '/everybody',
978-
href: '//[email protected]/everybody#to-the-limit',
979-
},
980-
981-
'http:@localhost': {
982-
protocol: 'http:',
983-
slashes: null,
984-
auth: null,
985-
host: 'localhost',
986-
port: null,
987-
hostname: 'localhost',
988-
hash: null,
989-
search: null,
990-
query: null,
991-
pathname: '/',
992-
path: '/',
993-
href: 'http://localhost/',
978+
href: '//[email protected]/everybody#to-the-limit'
994979
},
995980

996981
'\bhttp://example.com/\b': {

0 commit comments

Comments
 (0)