Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit ca4e86e

Browse files
committed
Merge pull request #3883 from jsha/no-match-rule
Remove match_rule and f attributes.
2 parents a78303b + 65c3244 commit ca4e86e

12 files changed

Lines changed: 22 additions & 151 deletions

File tree

chromium/rules.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@ function CookieRule(host, cookiename) {
4040
/**
4141
*A collection of rules
4242
* @param set_name The name of this set
43-
* @param match_rule Quick test match rule
4443
* @param default_state activity state
4544
* @param note Note will be displayed in popup
4645
* @constructor
4746
*/
48-
function RuleSet(set_name, match_rule, default_state, note) {
47+
function RuleSet(set_name, default_state, note) {
4948
this.name = set_name;
50-
if (match_rule)
51-
this.ruleset_match_c = new RegExp(match_rule);
52-
else
53-
this.ruleset_match_c = null;
5449
this.rules = [];
5550
this.exclusions = [];
5651
this.targets = [];
@@ -75,11 +70,6 @@ RuleSet.prototype = {
7570
return null;
7671
}
7772
}
78-
// If a ruleset has a match_rule and it fails, go no further
79-
if (this.ruleset_match_c && !this.ruleset_match_c.test(urispec)) {
80-
log(VERB, "ruleset_match_c excluded " + urispec);
81-
return null;
82-
}
8373

8474
// Okay, now find the first rule that triggers
8575
for(var i = 0; i < this.rules.length; ++i) {
@@ -89,12 +79,6 @@ RuleSet.prototype = {
8979
return returl;
9080
}
9181
}
92-
if (this.ruleset_match_c) {
93-
// This is not an error, because we do not insist the matchrule
94-
// precisely describes to target space of URLs ot redirected
95-
log(DBUG,"Ruleset "+this.name
96-
+" had an applicable match-rule but no matching rules");
97-
}
9882
return null;
9983
}
10084

@@ -162,7 +146,7 @@ RuleSets.prototype = {
162146
*/
163147
addUserRule : function(params) {
164148
log(INFO, 'adding new user rule for ' + JSON.stringify(params));
165-
var new_rule_set = new RuleSet(params.host, null, true, "user rule");
149+
var new_rule_set = new RuleSet(params.host, true, "user rule");
166150
var new_rule = new Rule(params.urlMatcher, params.redirectTo);
167151
new_rule_set.rules.push(new_rule);
168152
if (!(params.host in this.targets)) {
@@ -202,7 +186,6 @@ RuleSets.prototype = {
202186
}
203187

204188
var rule_set = new RuleSet(ruletag.getAttribute("name"),
205-
ruletag.getAttribute("match_rule"),
206189
default_state,
207190
note.trim());
208191

src/chrome/content/code/AndroidUI.jsm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ var popupInfo = {
106106
this.ruleItems.push({ label: rule, selected: true });
107107
this.ruleStatus.push(true);
108108
this.rules.push(this.alist.active[rule]);
109-
} else if (this.alist.moot.hasOwnProperty(rule)) {
110-
// moot rules are checked and toggleable too
111-
this.ruleItems.push({ label: rule, selected: true });
112-
this.ruleStatus.push(true);
113-
this.rules.push(this.alist.moot[rule]);
114109
} else if (this.alist.inactive.hasOwnProperty(rule)) {
115110
// inactive rules are unchecked and toggleable
116111
this.ruleItems.push({ label: rule });

src/chrome/content/code/ApplicableList.js

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ function ApplicableList(logger, uri) {
1717
this.active = {};
1818
this.breaking = {}; // rulesets with redirection loops
1919
this.inactive = {};
20-
this.moot={}; // rulesets that might be applicable but uris are already https
21-
this.all={}; // active + breaking + inactive + moot
20+
this.all={}; // active + breaking + inactive
2221
serial_number += 1;
2322
this.serial = serial_number;
2423
this.log(DBUG,"Alist serial #" + this.serial + " for " + this.home);
@@ -32,7 +31,6 @@ ApplicableList.prototype = {
3231
this.active = {};
3332
this.breaking = {};
3433
this.inactive = {};
35-
this.moot={};
3634
this.all={};
3735
},
3836

@@ -58,12 +56,6 @@ ApplicableList.prototype = {
5856
this.all[ruleset.name] = ruleset;
5957
},
6058

61-
moot_rule: function(ruleset) {
62-
this.log(INFO,"moot rule " + ruleset.name +" in "+ this.home + " serial " + this.serial);
63-
this.moot[ruleset.name] = ruleset;
64-
this.all[ruleset.name] = ruleset;
65-
},
66-
6759
dom_handler: function(operation,key,data,src,dst) {
6860
// See https://developer.mozilla.org/En/DOM/UserDataHandler
6961
if (src && dst)
@@ -182,19 +174,13 @@ ApplicableList.prototype = {
182174
this.add_command(this.breaking[x]);
183175
for(var x in this.active)
184176
this.add_command(this.active[x]);
185-
for(var x in this.moot)
186-
this.add_command(this.moot[x]);
187177
for(var x in this.inactive)
188178
this.add_command(this.inactive[x]);
189179

190180
if(https_everywhere.prefs.getBoolPref("globalEnabled")){
191181
// add all the menu items
192182
for (var x in this.inactive)
193183
this.add_menuitem(this.inactive[x], 'inactive');
194-
// rules that are active for some uris are not really moot
195-
for (var x in this.moot)
196-
if (!(x in this.active))
197-
this.add_menuitem(this.moot[x], 'moot');
198184
// break once break everywhere
199185
for (var x in this.active)
200186
if (!(x in this.breaking))
@@ -220,9 +206,8 @@ ApplicableList.prototype = {
220206
this.commandset.appendChild(command);
221207
},
222208

223-
// add a menu item for a rule -- type is "active", "inactive", "moot",
209+
// add a menu item for a rule -- type is "active", "inactive"
224210
// or "breaking"
225-
226211
add_menuitem: function(rule, type) {
227212
// create the menuitem
228213
var item = this.document.createElement('menuitem');
@@ -233,37 +218,20 @@ ApplicableList.prototype = {
233218

234219
// we can get confused if rulesets have their state changed after the
235220
// ApplicableList was constructed
236-
if (!rule.active && (type == 'active' || type == 'moot'))
221+
if (!rule.active && (type == 'active'))
237222
type = 'inactive';
238223
if (rule.active && type == 'inactive')
239-
type = 'moot';
240-
224+
type = 'active';
225+
241226
// set the icon
242227
var image_src;
243228
if (type == 'active') image_src = 'tick.png';
244229
else if (type == 'inactive') image_src = 'cross.png';
245-
else if (type == 'moot') image_src = 'tick-moot.png';
246230
else if (type == 'breaking') image_src = 'loop.png';
247231
item.setAttribute('image', 'chrome://https-everywhere/skin/'+image_src);
248232

249233
// all done
250234
this.prepend_child(item);
251-
},
252-
253-
show_applicable: function() {
254-
this.log(WARN, "Applicable list number " + this.serial);
255-
for (var x in this.active)
256-
this.log(WARN,"Active: " + this.active[x].name);
257-
258-
for (var x in this.breaking)
259-
this.log(WARN,"Breaking: " + this.breaking[x].name);
260-
261-
for (x in this.inactive)
262-
this.log(WARN,"Inactive: " + this.inactive[x].name);
263-
264-
for (x in this.moot)
265-
this.log(WARN,"Moot: " + this.moot[x].name);
266-
267235
}
268236
};
269237

src/chrome/content/code/HTTPSRules.js

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ function CookieRule(host, cookiename) {
1919
//this.name_c = new RegExp(cookiename);
2020
}
2121

22-
function RuleSet(id, name, xmlName, match_rule, default_off, platform) {
23-
if(xmlName == "WordPress.xml" || xmlName == "Github.xml") {
24-
this.log(NOTE, "RuleSet( name="+name+", xmlName="+xmlName+", match_rule="+match_rule+", default_off="+default_off+", platform="+platform+" )");
25-
}
26-
22+
function RuleSet(id, name, default_off, platform) {
2723
this.id=id;
2824
this.on_by_default = true;
2925
this.compiled = false;
3026
this.name = name;
31-
this.xmlName = xmlName;
3227
this.notes = "";
3328

34-
if (match_rule) this.ruleset_match_c = new RegExp(match_rule);
35-
else this.ruleset_match_c = null;
3629
if (default_off) {
3730
// Perhaps problematically, this currently ignores the actual content of
3831
// the default_off XML attribute. Ideally we'd like this attribute to be
@@ -93,12 +86,7 @@ RuleSet.prototype = {
9386
var i;
9487
var returl = null;
9588
this.ensureCompiled();
96-
// If a rulset has a match_rule and it fails, go no further
97-
if (this.ruleset_match_c && !this.ruleset_match_c.test(urispec)) {
98-
this.log(VERB, "ruleset_match_c excluded " + urispec);
99-
return null;
100-
}
101-
// Even so, if we're covered by an exclusion, go home
89+
// If we're covered by an exclusion, go home
10290
for (i = 0; i < this.exclusions.length; ++i) {
10391
if (this.exclusions[i].pattern_c.test(urispec)) {
10492
this.log(DBUG,"excluded uri " + urispec);
@@ -111,7 +99,7 @@ RuleSet.prototype = {
11199
returl = urispec.replace(this.rules[i].from_c, this.rules[i].to);
112100
if (returl != urispec) {
113101
// we rewrote the uri
114-
this.log(DBUG, "Rewrote " + urispec + " -> " + returl + " using " + this.xmlName + ": " + this.rules[i].from_c + " -> " + this.rules[i].to);
102+
this.log(DBUG, "Rewrote " + urispec + " -> " + returl + " using " + this.name + ": " + this.rules[i].from_c + " -> " + this.rules[i].to);
115103
return returl;
116104
}
117105
}
@@ -121,35 +109,6 @@ RuleSet.prototype = {
121109
log: function(level, msg) {
122110
https_everywhereLog(level, msg);
123111
},
124-
125-
wouldMatch: function(hypothetical_uri, alist) {
126-
// return true if this ruleset would match the uri, assuming it were http
127-
// used for judging moot / inactive rulesets
128-
// alist is optional
129-
130-
// if the ruleset is already somewhere in this applicable list, we don't
131-
// care about hypothetical wouldMatch questions
132-
if (alist && (this.name in alist.all)) return false;
133-
134-
this.log(DBUG,"Would " +this.name + " match " +hypothetical_uri.spec +
135-
"? serial " + (alist && alist.serial));
136-
137-
var uri = hypothetical_uri.clone();
138-
if (uri.scheme == "https") uri.scheme = "http";
139-
var urispec = uri.spec;
140-
141-
this.ensureCompiled();
142-
143-
if (this.ruleset_match_c && !this.ruleset_match_c.test(urispec))
144-
return false;
145-
146-
for (var i = 0; i < this.exclusions.length; ++i)
147-
if (this.exclusions[i].pattern_c.test(urispec)) return false;
148-
149-
for (var i = 0; i < this.rules.length; ++i)
150-
if (this.rules[i].from_c.test(urispec)) return true;
151-
return false;
152-
},
153112

154113
transformURI: function(uri) {
155114
// If no rule applies, return null; if a rule would have applied but was
@@ -309,10 +268,9 @@ const RuleWriter = {
309268

310269
this.log(DBUG, "Parsing " + xmlruleset.getAttribute("name"));
311270

312-
var match_rl = xmlruleset.getAttribute("match_rule");
313271
var dflt_off = xmlruleset.getAttribute("default_off");
314272
var platform = xmlruleset.getAttribute("platform");
315-
var rs = new RuleSet(ruleset_id, xmlruleset.getAttribute("name"), xmlruleset.getAttribute("f"), match_rl, dflt_off, platform);
273+
var rs = new RuleSet(ruleset_id, xmlruleset.getAttribute("name"), dflt_off, platform);
316274

317275
// see if this ruleset has the same name as an existing ruleset;
318276
// if so, this ruleset is ignored; DON'T add or return it.
@@ -498,31 +456,26 @@ const HTTPSRules = {
498456
}
499457

500458
// ponder each potentially applicable ruleset, working out if it applies
501-
// and recording it as active/inactive/moot/breaking in the applicable list
459+
// and recording it as active/inactive/breaking in the applicable list
502460
for (i = 0; i < rs.length; ++i) {
503461
if (!rs[i].active) {
504-
if (alist && rs[i].wouldMatch(uri, alist))
505-
alist.inactive_rule(rs[i]);
506-
continue;
507-
}
462+
alist.inactive_rule(rs[i]);
463+
}
508464
blob.newuri = rs[i].transformURI(uri);
509465
if (blob.newuri) {
510466
if (alist) {
511-
if (uri.spec in https_everywhere_blacklist)
467+
if (uri.spec in https_everywhere_blacklist) {
512468
alist.breaking_rule(rs[i]);
513-
else
469+
} else {
514470
alist.active_rule(rs[i]);
515-
}
516-
if (userpass_present) blob.newuri.userPass = input_uri.userPass;
471+
}
472+
}
473+
if (userpass_present) {
474+
blob.newuri.userPass = input_uri.userPass;
475+
}
517476
blob.applied_ruleset = rs[i];
518477
return blob;
519478
}
520-
if (uri.scheme == "https" && alist) {
521-
// we didn't rewrite but the rule applies to this domain and the
522-
// requests are going over https
523-
if (rs[i].wouldMatch(uri, alist)) alist.moot_rule(rs[i]);
524-
continue;
525-
}
526479
}
527480
return null;
528481
},
@@ -709,9 +662,6 @@ const HTTPSRules = {
709662
return true;
710663
}
711664
}
712-
if (ruleset.cookierules.length > 0 && applicable_list) {
713-
applicable_list.moot_rule(ruleset);
714-
}
715665
} else if (ruleset.cookierules.length > 0) {
716666
if (applicable_list) {
717667
applicable_list.inactive_rule(ruleset);

src/chrome/content/toolbar_button.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ httpsEverywhere.toolbarButton = {
198198
++counter;
199199
}
200200
}
201-
for (var x in alist.moot) {
202-
if (!(x in alist.active)) {
203-
++counter;
204-
}
205-
}
206201

207202
toolbarbutton.setAttribute('rulesetsApplied', counter);
208203
HTTPSEverywhere.log(INFO, 'Setting icon counter to: ' + counter);

src/chrome/skin/https-everywhere.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ toolbar[iconsize="small"] #https-everywhere-button[status="disabled"] > .https-e
6464
color: #1e6419;
6565
font-weight: bold;
6666
}
67-
#https-everywhere-button menuitem.moot-item label {
68-
color: #1e6419;
69-
opacity: 0.75;
70-
font-weight: bold;
71-
}
7267
#https-everywhere-button menuitem.breaking-item label {
7368
color: #b99999;
7469
font-weight: bold;

src/chrome/skin/tick-moot.png

-344 Bytes
Binary file not shown.

utils/make-sqlite.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@
8181
# pointing into the ruleset table.
8282
etree.strip_tags(tree, 'target')
8383

84-
# Store the filename in the `f' attribute so "view source XML" for rules in
85-
# FF version can find it.
86-
xpath_ruleset(tree)[0].attrib["f"] = os.path.basename(fi).decode(encoding="UTF-8")
87-
8884
c.execute('''INSERT INTO rulesets (contents) VALUES(?)''', (etree.tostring(tree),))
8985
ruleset_id = c.lastrowid
9086
for target in targets:

utils/merge-rulesets.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ def clean_up(rulefile):
7272
# Chromium
7373
library.write('<rulesetlibrary>')
7474

75-
# Include the filename.xml as the "f" attribute
7675
print("Removing whitespaces and comments...")
7776

7877
for rfile in sorted(xml_ruleset_files):
7978
ruleset = open(rfile).read()
80-
fn = os.path.basename(rfile)
81-
ruleset = ruleset.replace("<ruleset", '<ruleset f="%s"' % fn, 1)
8279
library.write(clean_up(ruleset))
8380
library.write("</rulesetlibrary>\n")
8481
library.close()

utils/relaxng.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<element xmlns="http://relaxng.org/ns/structure/1.0" name="ruleset" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
22
<attribute name="name" />
33

4-
<optional>
5-
<attribute name="match_rule" />
6-
</optional>
7-
84
<optional>
95
<attribute name="default_off" />
106
</optional>

0 commit comments

Comments
 (0)