Skip to content

Commit

Permalink
Add test ensuring regex .* not parsed as hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
msavva committed Mar 31, 2013
1 parent e7ffc26 commit 7fccfc2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/simple/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 7fccfc2

Please sign in to comment.