From 7fccfc28cd602389222523af30cb272689221178 Mon Sep 17 00:00:00 2001 From: Manolis Savva Date: Sun, 31 Mar 2013 14:34:17 -0700 Subject: [PATCH] Add test ensuring regex .* not parsed as hostname --- test/simple/test-url.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/simple/test-url.js b/test/simple/test-url.js index 6630da1025e..0313768ae02 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -1408,3 +1408,36 @@ relativeTests2.forEach(function(relativeTest) { 'format(' + relativeTest[1] + ') == ' + expected + '\nactual:' + actual); }); + +// Do not parse ".*" as a hostname (breaks regex matching in http-proxy) +var regexHostname = { + 'http://.*/': { + 'protocol': 'http:', + 'slashes': true, + 'host': '', + 'hostname': '', + 'path': '/', + 'pathname': '/', + 'href': 'http:///' + } +}; + +for (var u in regexHostname) { + var actual = url.parse(u); + var expected = regexHostname[u]; + + Object.keys(actual).forEach(function (i) { + if (expected[i] === undefined && actual[i] === null) { + expected[i] = null; + } + }); + + assert.deepEqual(actual, expected, + 'Regex .* should not parse as a host and hostname ("." is not a valid hostname)'); + + var expected = regexHostname[u].href, + actual = url.format(regexHostname[u]); + + assert.equal(actual, expected, + 'format(' + u + ') == ' + u + '\nactual:' + actual); +}