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

Side by Side Diff: test/abp2blocklist.js

Issue 29467595: Issue 5325 - Add support for separator characters (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Add special handling for separator at beginning Created June 19, 2017, 10:36 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/abp2blocklist.js ('K') | « lib/abp2blocklist.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // Element hiding rules should be in the following order: (1) generic 55 // Element hiding rules should be in the following order: (1) generic
56 // rules, (2) exceptions for generic rules, (3) domain-specific rules, 56 // rules, (2) exceptions for generic rules, (3) domain-specific rules,
57 // (4) exceptions for all rules. 57 // (4) exceptions for all rules.
58 testRules(test, [ 58 testRules(test, [
59 "##.whatever", 59 "##.whatever",
60 "test.com###something", 60 "test.com###something",
61 "@@||special.test.com^$elemhide", 61 "@@||special.test.com^$elemhide",
62 "@@||test.com^$generichide" 62 "@@||test.com^$generichide"
63 ], [ 63 ], [
64 ["^https?://", "css-display-none"], 64 ["^https?://", "css-display-none"],
65 ["^https?://([^/]+\\.)?test\\.com", "ignore-previous-rules"], 65 ["^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
66 "ignore-previous-rules"],
66 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"], 67 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"],
67 ["^https?://([^/]+\\.)?special\\.test\\.com", "ignore-previous-rules"] 68 ["^https?://([^/]+\\.)?special\\.test\\.com([^-_.%a-z0-9].*)?$",
69 "ignore-previous-rules"]
68 ], rules => rules.map(rule => [rule.trigger["url-filter"], 70 ], rules => rules.map(rule => [rule.trigger["url-filter"],
69 rule.action.type])); 71 rule.action.type]));
70 72
71 testRules(test, ["#@#whatever"], []); 73 testRules(test, ["#@#whatever"], []);
72 testRules(test, ["test.com#@#whatever"], []); 74 testRules(test, ["test.com#@#whatever"], []);
73 testRules(test, ["~test.com#@#whatever"], []); 75 testRules(test, ["~test.com#@#whatever"], []);
74 76
75 // We currently completely ignore any element hiding filters that have the 77 // We currently completely ignore any element hiding filters that have the
76 // same selector as an element hiding exception. In these examples #whatever 78 // same selector as an element hiding exception. In these examples #whatever
77 // should be hidden for all domains not ending in test.com instead of 79 // should be hidden for all domains not ending in test.com instead of
78 // nowhere! 80 // nowhere!
79 testRules(test, ["test.com#@#whatever", "##whatever"], []); 81 testRules(test, ["test.com#@#whatever", "##whatever"], []);
80 testRules(test, ["~test.com##whatever"], []); 82 testRules(test, ["~test.com##whatever"], []);
81 83
82 test.done(); 84 test.done();
83 }, 85 },
84 86
85 testRequestFilters: function(test) 87 testRequestFilters: function(test)
86 { 88 {
87 testRules(test, ["/foo", "||test.com", "http://example.com/foo"], [ 89 testRules(test, ["/foo", "||test.com^", "http://example.com/foo", "^foo^"], [
88 {trigger: {"url-filter": "^https?://.*/foo", 90 {trigger: {"url-filter": "^https?://.*/foo",
89 "resource-type": ["image", "style-sheet", "script", "font", 91 "resource-type": ["image", "style-sheet", "script", "font",
90 "media", "raw", "document"], 92 "media", "raw", "document"],
91 "unless-top-url": ["^https?://.*/foo"]}, 93 "unless-top-url": ["^https?://.*/foo"]},
92 action: {type: "block"}}, 94 action: {type: "block"}},
93 {trigger: {"url-filter": "^https?://([^/]+\\.)?test\\.com", 95 {trigger: {"url-filter": "^https?://([^/]+\\.)?test\\.com([^-_.%a-z0-9].*) ?$",
94 "url-filter-is-case-sensitive": true, 96 "url-filter-is-case-sensitive": true,
95 "resource-type": ["image", "style-sheet", "script", "font", 97 "resource-type": ["image", "style-sheet", "script", "font",
96 "media", "raw", "document"], 98 "media", "raw", "document"],
97 "unless-top-url": ["^https?://([^/]+\\.)?test\\.com"], 99 "unless-top-url": ["^https?://([^/]+\\.)?test\\.com([^-_.%a-z0- 9].*)?$"],
98 "top-url-filter-is-case-sensitive": true}, 100 "top-url-filter-is-case-sensitive": true},
99 action: {type: "block"}}, 101 action: {type: "block"}},
100 {trigger: {"url-filter": "http://example\\.com/foo", 102 {trigger: {"url-filter": "http://example\\.com/foo",
101 "resource-type": ["image", "style-sheet", "script", "font", 103 "resource-type": ["image", "style-sheet", "script", "font",
102 "media", "raw", "document"], 104 "media", "raw", "document"],
103 "unless-top-url": ["http://example\\.com/foo"]}, 105 "unless-top-url": ["http://example\\.com/foo"]},
106 action: {type: "block"}},
107 {trigger: {"url-filter": "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0 -9].*)?$",
108 "resource-type": ["image", "style-sheet", "script", "font",
109 "media", "raw", "document"],
110 "unless-top-url": ["^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A- Za-z0-9].*)?$"]},
104 action: {type: "block"}} 111 action: {type: "block"}}
105 ]); 112 ]);
106 113
107 testRules(test, ["||example.com"], [ 114 testRules(test, ["||example.com"], [
108 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 115 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com",
109 "url-filter-is-case-sensitive": true, 116 "url-filter-is-case-sensitive": true,
110 "resource-type": ["image", "style-sheet", "script", "font", 117 "resource-type": ["image", "style-sheet", "script", "font",
111 "media", "raw", "document"], 118 "media", "raw", "document"],
112 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], 119 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"],
113 "top-url-filter-is-case-sensitive": true}, 120 "top-url-filter-is-case-sensitive": true},
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 { 162 {
156 testRules(test, ["@@||example.com^$document"], [ 163 testRules(test, ["@@||example.com^$document"], [
157 {trigger: {"url-filter": ".*", 164 {trigger: {"url-filter": ".*",
158 "if-domain": ["*example.com"]}, 165 "if-domain": ["*example.com"]},
159 action: {type: "ignore-previous-rules"}} 166 action: {type: "ignore-previous-rules"}}
160 ]); 167 ]);
161 testRules(test, ["@@||example.com^$document,image"], [ 168 testRules(test, ["@@||example.com^$document,image"], [
162 {trigger: {"url-filter": ".*", 169 {trigger: {"url-filter": ".*",
163 "if-domain": ["*example.com"]}, 170 "if-domain": ["*example.com"]},
164 action: {type: "ignore-previous-rules"}}, 171 action: {type: "ignore-previous-rules"}},
165 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 172 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9] .*)?$",
166 "url-filter-is-case-sensitive": true, 173 "url-filter-is-case-sensitive": true,
167 "resource-type": ["image"]}, 174 "resource-type": ["image"]},
168 action: {type: "ignore-previous-rules"}} 175 action: {type: "ignore-previous-rules"}}
169 ]); 176 ]);
170 testRules(test, ["@@||example.com/path^$font,document"], [ 177 testRules(test, ["@@||example.com/path^$font,document"], [
171 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path", 178 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path([^-_.%A- Za-z0-9].*)?$",
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.
172 "resource-type": ["font"]}, 179 "resource-type": ["font"]},
173 action: {type: "ignore-previous-rules"}} 180 action: {type: "ignore-previous-rules"}}
174 ]); 181 ]);
175 182
176 test.done(); 183 test.done();
177 }, 184 },
178 185
179 testGenericblockExceptions: function(test) 186 testGenericblockExceptions: function(test)
180 { 187 {
181 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 188 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 testUnicode: function(test) 282 testUnicode: function(test)
276 { 283 {
277 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 284 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
278 rules => rules[0]["trigger"]["if-domain"]); 285 rules => rules[0]["trigger"]["if-domain"]);
279 testRules(test, ["🐈$domain=🐈.cat"], []); 286 testRules(test, ["🐈$domain=🐈.cat"], []);
280 testRules(test, ["###🐈"], []); 287 testRules(test, ["###🐈"], []);
281 288
282 test.done(); 289 test.done();
283 } 290 }
284 }; 291 };
OLDNEW
« lib/abp2blocklist.js ('K') | « lib/abp2blocklist.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld