Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/abp2blocklist.js

Issue 29467595: Issue 5325 - Add support for separator characters (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Left Patch Set: Add special handling for separator at beginning Created June 19, 2017, 10:36 a.m.
Right Patch Set: Rebase Created July 12, 2017, 12:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/abp2blocklist.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 {trigger: {"url-filter": "^https?://([^/:]*\\.)?test\\.com[/:]", 45 {trigger: {"url-filter": "^https?://([^/:]*\\.)?test\\.com[/:]",
46 "url-filter-is-case-sensitive": true}, 46 "url-filter-is-case-sensitive": true},
47 action: {type: "css-display-none", selector: ".whatever"}} 47 action: {type: "css-display-none", selector: ".whatever"}}
48 ]); 48 ]);
49 49
50 test.done(); 50 test.done();
51 }, 51 },
52 52
53 testElementHidingExceptions: function(test) 53 testElementHidingExceptions: function(test)
54 { 54 {
55 // Element hiding rules should be in the following order: (1) generic
56 // rules, (2) exceptions for generic rules, (3) domain-specific rules,
57 // (4) exceptions for all rules.
58 testRules(test, [ 55 testRules(test, [
59 "##.whatever", 56 "##.whatever",
60 "test.com###something", 57 "test.com###something",
61 "@@||special.test.com^$elemhide", 58 "@@||special.test.com^$elemhide",
62 "@@||test.com^$generichide" 59 "@@||test.com^$generichide",
60 "@@^something^$elemhide",
61 "@@^anything^$generichide"
63 ], [ 62 ], [
64 ["^https?://", "css-display-none"], 63 ["^https?://", ["*test.com", "*special.test.com"]],
65 ["^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$", 64 ["^https?://([^/:]*\\.)?test\\.com[/:]", ["*special.test.com"]]
66 "ignore-previous-rules"],
67 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"],
68 ["^https?://([^/]+\\.)?special\\.test\\.com([^-_.%a-z0-9].*)?$",
69 "ignore-previous-rules"]
70 ], rules => rules.map(rule => [rule.trigger["url-filter"], 65 ], rules => rules.map(rule => [rule.trigger["url-filter"],
71 rule.action.type])); 66 rule.trigger["unless-domain"]]));
72 67
73 testRules(test, ["#@#whatever"], []); 68 testRules(test, ["#@#whatever"], []);
74 testRules(test, ["test.com#@#whatever"], []); 69 testRules(test, ["test.com#@#whatever"], []);
75 testRules(test, ["~test.com#@#whatever"], []); 70 testRules(test, ["~test.com#@#whatever"], []);
76 71
77 // We currently completely ignore any element hiding filters that have the 72 // We currently completely ignore any element hiding filters that have the
78 // same selector as an element hiding exception. In these examples #whatever 73 // same selector as an element hiding exception. In these examples #whatever
79 // should be hidden for all domains not ending in test.com instead of 74 // should be hidden for all domains not ending in test.com instead of
80 // nowhere! 75 // nowhere!
81 testRules(test, ["test.com#@#whatever", "##whatever"], []); 76 testRules(test, ["test.com#@#whatever", "##whatever"], []);
82 testRules(test, ["~test.com##whatever"], []); 77 testRules(test, ["~test.com##whatever"], []);
83 78
84 test.done(); 79 test.done();
85 }, 80 },
86 81
87 testRequestFilters: function(test) 82 testRequestFilters: function(test)
88 { 83 {
89 testRules(test, ["/foo", "||test.com^", "http://example.com/foo", "^foo^"], [ 84 testRules(test, [
90 {trigger: {"url-filter": "^https?://.*/foo", 85 "/foo", "||test.com^", "http://example.com/foo", "^foo^"
91 "resource-type": ["image", "style-sheet", "script", "font", 86 ], [
92 "media", "raw", "document"], 87 {
93 "unless-top-url": ["^https?://.*/foo"]}, 88 trigger: {
94 action: {type: "block"}}, 89 "url-filter": "^https?://.*/foo",
95 {trigger: {"url-filter": "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*) ?$", 90 "resource-type": ["image", "style-sheet", "script", "font",
96 "url-filter-is-case-sensitive": true, 91 "media", "raw"]
97 "resource-type": ["image", "style-sheet", "script", "font", 92 },
98 "media", "raw", "document"], 93 action: {type: "block"}
99 "unless-top-url": ["^https?://([^/]+\\.)?test\\.com([^-_.%a-z0- 9].*)?$"], 94 },
100 "top-url-filter-is-case-sensitive": true}, 95 {
101 action: {type: "block"}}, 96 trigger: {
102 {trigger: {"url-filter": "http://example\\.com/foo", 97 "url-filter": "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
103 "resource-type": ["image", "style-sheet", "script", "font", 98 "url-filter-is-case-sensitive": true,
104 "media", "raw", "document"], 99 "resource-type": ["image", "style-sheet", "script", "font",
105 "unless-top-url": ["http://example\\.com/foo"]}, 100 "media", "raw", "document"],
106 action: {type: "block"}}, 101 "unless-top-url": [
107 {trigger: {"url-filter": "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0 -9].*)?$", 102 "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$"
108 "resource-type": ["image", "style-sheet", "script", "font", 103 ],
109 "media", "raw", "document"], 104 "top-url-filter-is-case-sensitive": true
110 "unless-top-url": ["^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A- Za-z0-9].*)?$"]}, 105 },
111 action: {type: "block"}} 106 action: {type: "block"}
107 },
108 {
109 trigger: {
110 "url-filter": "http://example\\.com/foo",
111 "resource-type": ["image", "style-sheet", "script", "font",
112 "media", "raw", "document"],
113 "unless-top-url": ["http://example\\.com/foo"]
114 },
115 action: {type: "block"}
116 },
117 {
118 trigger: {
119 "url-filter":
120 "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$",
121 "resource-type": ["image", "style-sheet", "script", "font",
122 "media", "raw"]
123 },
124 action: {type: "block"}
125 }
112 ]); 126 ]);
113 127
114 testRules(test, ["||example.com"], [ 128 testRules(test, ["||example.com"], [
115 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 129 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com",
116 "url-filter-is-case-sensitive": true, 130 "url-filter-is-case-sensitive": true,
117 "resource-type": ["image", "style-sheet", "script", "font", 131 "resource-type": ["image", "style-sheet", "script", "font",
118 "media", "raw", "document"], 132 "media", "raw", "document"],
119 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], 133 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"],
120 "top-url-filter-is-case-sensitive": true}, 134 "top-url-filter-is-case-sensitive": true},
121 135
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ["###example", "test.com###EXAMPLE"], 168 ["###example", "test.com###EXAMPLE"],
155 ["[id=example]", "[id=EXAMPLE]"], 169 ["[id=example]", "[id=EXAMPLE]"],
156 rules => rules.map(rule => rule.action.selector)); 170 rules => rules.map(rule => rule.action.selector));
157 171
158 test.done(); 172 test.done();
159 }, 173 },
160 174
161 testDomainWhitelisting: function(test) 175 testDomainWhitelisting: function(test)
162 { 176 {
163 testRules(test, ["@@||example.com^$document"], [ 177 testRules(test, ["@@||example.com^$document"], [
164 {trigger: {"url-filter": ".*", 178 {
165 "if-domain": ["*example.com"]}, 179 trigger: {
166 action: {type: "ignore-previous-rules"}} 180 "url-filter": ".*",
181 "if-domain": ["*example.com"]
182 },
183 action: {type: "ignore-previous-rules"}
184 }
167 ]); 185 ]);
168 testRules(test, ["@@||example.com^$document,image"], [ 186 testRules(test, ["@@||example.com^$document,image"], [
169 {trigger: {"url-filter": ".*", 187 {
170 "if-domain": ["*example.com"]}, 188 trigger: {
171 action: {type: "ignore-previous-rules"}}, 189 "url-filter": ".*",
172 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9] .*)?$", 190 "if-domain": ["*example.com"]
173 "url-filter-is-case-sensitive": true, 191 },
174 "resource-type": ["image"]}, 192 action: {type: "ignore-previous-rules"}
175 action: {type: "ignore-previous-rules"}} 193 },
194 {
195 trigger: {
196 "url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9].*)?$",
197 "url-filter-is-case-sensitive": true,
198 "resource-type": ["image"]
199 },
200 action: {type: "ignore-previous-rules"}
201 }
176 ]); 202 ]);
177 testRules(test, ["@@||example.com/path^$font,document"], [ 203 testRules(test, ["@@||example.com/path^$font,document"], [
178 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path([^-_.%A- Za-z0-9].*)?$", 204 {
kzar 2017/07/07 12:46:18 Nit: Mind fixing these long lines where possible?
Manish Jethani 2017/07/08 06:33:57 Acknowledged. I'll try to fix this.
Manish Jethani 2017/07/09 10:50:52 Done.
179 "resource-type": ["font"]}, 205 trigger: {
180 action: {type: "ignore-previous-rules"}} 206 "url-filter":
207 "^https?://([^/]+\\.)?example\\.com/path([^-_.%A-Za-z0-9].*)?$",
208 "resource-type": ["font"]
209 },
210 action: {type: "ignore-previous-rules"}
211 }
181 ]); 212 ]);
182 213
183 test.done(); 214 test.done();
184 }, 215 },
185 216
186 testGenericblockExceptions: function(test) 217 testGenericblockExceptions: function(test)
187 { 218 {
188 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 219 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
189 [[undefined, ["*example.com"]]], 220 [[undefined, ["*example.com"]]],
190 rules => rules.map(rule => [rule.trigger["if-domain"], 221 rules => rules.map(rule => [rule.trigger["if-domain"],
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 }, 253 },
223 254
224 testRequestTypeMapping: function(test) 255 testRequestTypeMapping: function(test)
225 { 256 {
226 testRules( 257 testRules(
227 test, 258 test,
228 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 259 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
229 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 260 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
230 "11$ping", "12$subdocument", "13$other", "14$IMAGE", 261 "11$ping", "12$subdocument", "13$other", "14$IMAGE",
231 "15$script,PING,Popup", "16$~image"], 262 "15$script,PING,Popup", "16$~image"],
232 [["image", "style-sheet", "script", "font", "media", "raw", "document" ], 263 [["image", "style-sheet", "script", "font", "media", "raw"],
233 ["image"], 264 ["image"],
234 ["style-sheet"], 265 ["style-sheet"],
235 ["script"], 266 ["script"],
236 ["font"], 267 ["font"],
237 ["media"], 268 ["media"],
238 ["popup"], 269 ["popup"],
239 ["media"], 270 ["media"],
240 ["raw"], 271 ["raw"],
241 ["raw"], 272 ["raw"],
242 ["raw"], 273 ["raw"],
243 ["document"],
244 ["raw"], 274 ["raw"],
245 ["image"], 275 ["image"],
246 ["script", "popup", "raw" ], 276 ["script", "popup", "raw" ],
247 ["style-sheet", "script", "font", "media", "raw", "document"]], 277 ["style-sheet", "script", "font", "media", "raw"]],
248 rules => rules.map(rule => rule.trigger["resource-type"]) 278 rules => rules.map(rule => rule.trigger["resource-type"])
249 ); 279 );
250 280
251 test.done(); 281 test.done();
252 }, 282 },
253 283
254 testUnsupportedfilters: function(test) 284 testUnsupportedfilters: function(test)
255 { 285 {
256 // These types of filters are currently completely unsupported. 286 // These types of filters are currently completely unsupported.
257 testRules(test, ["foo$sitekey=bar"], []); 287 testRules(test, ["foo$sitekey=bar"], []);
(...skipping 18 matching lines...) Expand all
276 ["foo.com"], 306 ["foo.com"],
277 rules => rules[0]["trigger"]["if-domain"]); 307 rules => rules[0]["trigger"]["if-domain"]);
278 308
279 test.done(); 309 test.done();
280 }, 310 },
281 311
282 testUnicode: function(test) 312 testUnicode: function(test)
283 { 313 {
284 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 314 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
285 rules => rules[0]["trigger"]["if-domain"]); 315 rules => rules[0]["trigger"]["if-domain"]);
286 testRules(test, ["🐈$domain=🐈.cat"], []); 316 testRules(test, ["||🐈"], "^https?://([^/]+\\.)?xn--zn8h",
287 testRules(test, ["###🐈"], []); 317 rules => rules[0]["trigger"]["url-filter"]);
318 testRules(test, ["🐈$domain=🐈.cat"], "^https?://.*%F0%9F%90%88",
319 rules => rules[0]["trigger"]["url-filter"]);
320 testRules(test, ["🐈%F0%9F%90%88$domain=🐈.cat"],
321 "^https?://.*%F0%9F%90%88%F0%9F%90%88",
322 rules => rules[0]["trigger"]["url-filter"]);
323 testRules(test, ["###🐈"], "[id=🐈]",
324 rules => rules[0]["action"]["selector"]);
288 325
289 test.done(); 326 test.done();
290 } 327 }
291 }; 328 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld