Skip to content

Commit

Permalink
using the correct string conversion utility
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 4, 2015
1 parent 5274c1d commit 523132e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ var chrome = require("chrome");
var Cc = chrome.Cc;
var Ci = chrome.Ci;

var cvtUTF8 = (function(contractId, intf) {
return Cc[contractId].createInstance(Ci[intf]);
}("@mozilla.org/intl/scriptableunicodeconverter",
"nsIScriptableUnicodeConverter"));

function AbstractPattern(apply) {
if (!apply) { return; }
var prop;
Expand Down Expand Up @@ -49,14 +54,6 @@ NegRespTagPattern.prototype = new AbstractPattern({
}
});

var cStringConvert = (function(contractId, intf) {
return Cc[contractId].createInstance(Ci[intf]);
}("@mozilla.org/supports-cstring;1", "nsISupportsCString"));
function utf8ToString(utf8) {
cStringConvert.data = utf8;
return cStringConvert.toString();
}

/*jslint regexp: true */
var hostGlobRE = /\[[\-a-z0-9.]+\]|\.|\?|\*|[^\-a-z0-9.]/g;
/*jslint regexp: false */
Expand Down Expand Up @@ -87,7 +84,7 @@ function HostPattern(pattern) {
}
HostPattern.prototype = new AbstractPattern({
testURI: function testURI(uri) {
var host = utf8ToString(uri.host);
var host = cvtUTF8.ConvertToUnicode(uri.host);
return this.hostRE.test(host);
},
testRequest: function testRequest(req) {
Expand All @@ -113,8 +110,8 @@ function PathPattern(pattern) {
}
PathPattern.prototype = new AbstractPattern({
testURI: function testURI(uri) {
var host = utf8ToString(uri.host);
var path = utf8ToString(uri.path);
var host = cvtUTF8.ConvertToUnicode(uri.host);
var path = cvtUTF8.ConvertToUnicode(uri.path);
return this.hostRE.test(host) && this.pathRE.test(path);
},
testRequest: function testRequest(req) {
Expand Down

0 comments on commit 523132e

Please sign in to comment.