Skip to content

Commit

Permalink
another test, another bugfix as a result
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 5, 2015
1 parent dab7b17 commit 6201303
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function globToRE(str) {
return (str.length > 1) ? str : "";
}
function matchDomain(str) {
return str ? "\\.?" : "^";
return str ? "^([-a-z0-9]+\\.)*" : "^";
}
function hostGlobToRE(host) {
var re = host.replace(hostGlobRE, globToRE);
Expand Down
34 changes: 34 additions & 0 deletions test/test-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,38 @@ exports["test partial host match"] = function(assert) {
"Wildcard host match response");
}

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

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

0 comments on commit 6201303

Please sign in to comment.