diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-20 12:24:35 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-27 17:05:17 +0100 |
commit | bbfa93af3d1577fbf96622c9100c07d45ff8998a (patch) | |
tree | 026f14e7dc70011ad519241859a808fda3453de5 /lib/url.js | |
parent | ce265908eb84aa0518dcadc57d59e7fbb353a256 (diff) | |
download | android-node-v8-bbfa93af3d1577fbf96622c9100c07d45ff8998a.tar.gz android-node-v8-bbfa93af3d1577fbf96622c9100c07d45ff8998a.tar.bz2 android-node-v8-bbfa93af3d1577fbf96622c9100c07d45ff8998a.zip |
url: refactor validateHostname
This function did not only validate the input but it returned a new
value in case the hostname was valid. This simplifies the function
by always returning the required value, no matter if it is valid or
invalid, so the callee site does not have to check that anymore. On
top the function is renamed to `getHostname` to make clear that the
function does not only validate the input but it also returns a new
value.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/url.js')
-rw-r--r-- | lib/url.js | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/url.js b/lib/url.js index ade0007171..f50d180c7a 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. |