diff --git a/lib/url.js b/lib/url.js index ade0007171ee48..f50d180c7a1585 100644 --- a/lib/url.js +++ b/lib/url.js @@ -359,9 +359,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { // validate a little. if (!ipv6Hostname) { - const result = validateHostname(this, rest, hostname); - if (result !== undefined) - rest = result; + rest = getHostname(this, rest, hostname); } if (this.hostname.length > hostnameMaxLen) { @@ -462,7 +460,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { return this; }; -function validateHostname(self, rest, hostname) { +function getHostname(self, rest, hostname) { for (var i = 0; i < hostname.length; ++i) { const code = hostname.charCodeAt(i); const isValid = (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) || @@ -477,9 +475,10 @@ function validateHostname(self, rest, hostname) { // Invalid host character if (!isValid) { self.hostname = hostname.slice(0, i); - return '/' + hostname.slice(i) + rest; + return `/${hostname.slice(i)}${rest}`; } } + return rest; } // Escaped characters. Use empty strings to fill up unused entries.