Skip to content

Commit

Permalink
new test, fix for exposed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 5, 2015
1 parent 69fcdee commit dab7b17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ HostPattern.prototype = new AbstractPattern({
});

/*jslint regexp: true */
var pathRE = /^([\-.\[\]a-z0-9]*)(\/.+)$/;
var pathRE = /^([\-.\[\]a-z0-9*?]*)(\/.+)$/;
/*jslint regexp: false */
var fakeRE = { test: function() { return true; } };
function PathPattern(pattern) {
Expand All @@ -107,7 +107,7 @@ PathPattern.prototype = new AbstractPattern({
var tagRE = /^TAG:/;
var negReqTagRE = /^NO-REQUEST-TAG:/;
var negRespTagRE = /^NO-RESPONSE-TAG:/;
var hostRE = /^([\-.\[\]a-z0-9]+)\/?$/;
var hostRE = /^([\-.\[\]a-z0-9*?]+)\/?$/;
function createPattern(pattern) {
pattern = pattern.trim();
if (tagRE.test(pattern)) {
Expand Down
29 changes: 29 additions & 0 deletions test/test-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,33 @@ exports["test exact host match"] = function(assert) {
"Exact host match response");
}

exports["test partial host match"] = function(assert) {
var channel = createMockChannel("www.example.com", "/");
var matcher = new Matcher([ "www." ]);
assert.strictEqual(matcher.testRequest(channel), true,
"Prefix host match request");
assert.strictEqual(matcher.testResponse(channel), true,
"Prefix host match response");
var matcher = new Matcher([ ".example.com" ]);
assert.strictEqual(matcher.testRequest(channel), true,
"Suffix host match request");
assert.strictEqual(matcher.testResponse(channel), true,
"Suffix host match response");
var matcher = new Matcher([ ".example." ]);
assert.strictEqual(matcher.testRequest(channel), true,
"Middle host match request");
assert.strictEqual(matcher.testResponse(channel), true,
"Middle host match response");
var matcher = new Matcher([ "www.exam*.com" ]);
assert.strictEqual(matcher.testRequest(channel), true,
"Glob host match request");
assert.strictEqual(matcher.testResponse(channel), true,
"Glob host match response");
var matcher = new Matcher([ "www.exa??le.com" ]);
assert.strictEqual(matcher.testRequest(channel), true,
"Wildcard host match request");
assert.strictEqual(matcher.testResponse(channel), true,
"Wildcard host match response");
}

require("sdk/test").run(exports);

0 comments on commit dab7b17

Please sign in to comment.