diff --git a/lib/url.js b/lib/url.js index ab82cc2abbd8e8..d754fea3b25359 100644 --- a/lib/url.js +++ b/lib/url.js @@ -358,9 +358,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { // First, make 100% sure that any "autoEscape" chars get // escaped, even if encodeURIComponent doesn't think they // need to be. - const result = autoEscapeStr(rest); - if (result !== undefined) - rest = result; + rest = autoEscapeStr(rest); } var questionIdx = -1; @@ -441,8 +439,7 @@ function validateHostname(self, rest, hostname) { // Automatically escape all delimiters and unwise characters from RFC 2396. // Also escape single quotes in case of an XSS attack. -// Return undefined if the string doesn't need escaping, -// otherwise return the escaped string. +// Return the escaped string. function autoEscapeStr(rest) { var escaped = ''; var lastEscapedPos = 0; @@ -538,12 +535,13 @@ function autoEscapeStr(rest) { } } if (lastEscapedPos === 0) // Nothing has been escaped. - return; + return rest; + // There are ordinary characters at the end. if (lastEscapedPos < rest.length) - return escaped + rest.slice(lastEscapedPos); - else // The last character is escaped. - return escaped; + escaped += rest.slice(lastEscapedPos); + + return escaped; } // format a parsed object into a url string