From 3ac9e01faaf4b16b63008b6e38243d4d5fa35a66 Mon Sep 17 00:00:00 2001 From: Axel Monroy Date: Tue, 6 Dec 2016 11:04:00 -0700 Subject: [PATCH] url: add a got host pattern in url.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a hostPattern variable for readable purposes PR-URL: https://github.com/nodejs/node/pull/9653 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso Reviewed-By: Brian White --- lib/url.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index 106fb47f88..1437443e75 100644 --- a/lib/url.js +++ b/lib/url.js @@ -38,6 +38,7 @@ function Url() { // compiled once on the first module load. const protocolPattern = /^([a-z0-9.+-]+:)/i; const portPattern = /:[0-9]*$/; +const hostPattern = /^\/\/[^@/]+@[^@/]+/; // Special case for a simple path URL const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/; @@ -200,7 +201,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { // 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. - if (slashesDenoteHost || proto || /^\/\/[^@/]+@[^@/]+/.test(rest)) { + if (slashesDenoteHost || proto || hostPattern.test(rest)) { var slashes = rest.charCodeAt(0) === 47/*/*/ && rest.charCodeAt(1) === 47/*/*/; if (slashes && !(proto && hostlessProtocol[proto])) {