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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Make snippet filters similar to element hiding filters Created April 25, 2018, 5:15 p.m.
Right Patch Set: Improve comment formatting Created July 11, 2018, 1:02 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
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let Filter = null; 22 let Filter = null;
23 let InvalidFilter = null; 23 let InvalidFilter = null;
24 let CommentFilter = null; 24 let CommentFilter = null;
25 let ActiveFilter = null; 25 let ActiveFilter = null;
26 let RegExpFilter = null; 26 let RegExpFilter = null;
27 let BlockingFilter = null; 27 let BlockingFilter = null;
28 let ContentFilter = null;
28 let WhitelistFilter = null; 29 let WhitelistFilter = null;
29 let ElemHideBase = null; 30 let ElemHideBase = null;
30 let ElemHideFilter = null; 31 let ElemHideFilter = null;
31 let ElemHideException = null; 32 let ElemHideException = null;
32 let ElemHideEmulationFilter = null; 33 let ElemHideEmulationFilter = null;
34 let SnippetFilter = null;
33 35
34 let t = null; 36 let t = null;
35 let defaultTypes = null; 37 let defaultTypes = null;
36 38
37 exports.setUp = function(callback) 39 exports.setUp = function(callback)
38 { 40 {
39 let sandboxedRequire = createSandbox(); 41 let sandboxedRequire = createSandbox();
40 ( 42 (
41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, 43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, 44 BlockingFilter, WhitelistFilter, ContentFilter, ElemHideBase,
43 ElemHideException, 45 ElemHideFilter, ElemHideException, ElemHideEmulationFilter,
44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") 46 SnippetFilter} = sandboxedRequire("../lib/filterClasses")
45 ); 47 );
46 t = RegExpFilter.typeMap; 48 t = RegExpFilter.typeMap;
47 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.SNIPPET | t.DOCUMENT | 49 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP |
48 t.POPUP | t.GENERICHIDE | t.GENERICBLOCK); 50 t.GENERICHIDE | t.GENERICBLOCK);
49 51
50 callback(); 52 callback();
51 }; 53 };
52 54
53 function serializeFilter(filter) 55 function serializeFilter(filter)
54 { 56 {
55 // Filter serialization only writes out essential properties, need to do a ful l serialization here 57 // Filter serialization only writes out essential properties, need to do a ful l serialization here
56 let result = []; 58 let result = [];
57 result.push("text=" + filter.text); 59 result.push("text=" + filter.text);
58 if (filter instanceof InvalidFilter) 60 if (filter instanceof InvalidFilter)
(...skipping 28 matching lines...) Expand all
87 89
88 let sitekeys = filter.sitekeys || []; 90 let sitekeys = filter.sitekeys || [];
89 result.push("sitekeys=" + sitekeys.slice().sort().join("|")); 91 result.push("sitekeys=" + sitekeys.slice().sort().join("|"));
90 92
91 result.push("thirdParty=" + filter.thirdParty); 93 result.push("thirdParty=" + filter.thirdParty);
92 if (filter instanceof BlockingFilter) 94 if (filter instanceof BlockingFilter)
93 { 95 {
94 result.push("type=filterlist"); 96 result.push("type=filterlist");
95 result.push("collapse=" + filter.collapse); 97 result.push("collapse=" + filter.collapse);
96 result.push("csp=" + filter.csp); 98 result.push("csp=" + filter.csp);
99 result.push("rewrite=" + filter.rewrite);
97 } 100 }
98 else if (filter instanceof WhitelistFilter) 101 else if (filter instanceof WhitelistFilter)
99 result.push("type=whitelist"); 102 result.push("type=whitelist");
100 } 103 }
101 else if (filter instanceof ElemHideBase) 104 else if (filter instanceof ElemHideBase)
102 { 105 {
103 if (filter instanceof ElemHideFilter) 106 if (filter instanceof ElemHideFilter)
104 result.push("type=elemhide"); 107 result.push("type=elemhide");
105 else if (filter instanceof ElemHideException) 108 else if (filter instanceof ElemHideException)
106 result.push("type=elemhideexception"); 109 result.push("type=elemhideexception");
107 else if (filter instanceof ElemHideEmulationFilter) 110 else if (filter instanceof ElemHideEmulationFilter)
108 result.push("type=elemhideemulation"); 111 result.push("type=elemhideemulation");
109 112
110 result.push("injectionDomain=" + (filter.injectionDomain || "")); 113 result.push("selectorDomains=" +
111 result.push("code=" + filter.code); 114 [...filter.domains || []]
115 .filter(([domain, isIncluded]) => isIncluded)
116 .map(([domain]) => domain.toLowerCase()));
117 result.push("selector=" + filter.selector);
118 }
119 else if (filter instanceof SnippetFilter)
120 {
121 result.push("type=snippet");
122 result.push("scriptDomains=" +
123 [...filter.domains || []]
124 .filter(([domain, isIncluded]) => isIncluded)
125 .map(([domain]) => domain.toLowerCase()));
126 result.push("script=" + filter.script);
112 } 127 }
113 } 128 }
114 return result; 129 return result;
115 } 130 }
116 131
117 function addDefaults(expected) 132 function addDefaults(expected)
118 { 133 {
119 let type = null; 134 let type = null;
120 let hasProperty = {}; 135 let hasProperty = {};
121 for (let entry of expected) 136 for (let entry of expected)
122 { 137 {
123 if (/^type=(.*)/.test(entry)) 138 if (/^type=(.*)/.test(entry))
124 type = RegExp.$1; 139 type = RegExp.$1;
125 else if (/^(\w+)/.test(entry)) 140 else if (/^(\w+)/.test(entry))
126 hasProperty[RegExp.$1] = true; 141 hasProperty[RegExp.$1] = true;
127 } 142 }
128 143
129 function addProperty(prop, value) 144 function addProperty(prop, value)
130 { 145 {
131 if (!(prop in hasProperty)) 146 if (!(prop in hasProperty))
132 expected.push(prop + "=" + value); 147 expected.push(prop + "=" + value);
133 } 148 }
134 149
135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || 150 if (type == "whitelist" || type == "filterlist" || type == "elemhide" ||
136 type == "elemhideexception" || type == "elemhideemulation") 151 type == "elemhideexception" || type == "elemhideemulation" ||
152 type == "snippet")
137 { 153 {
138 addProperty("disabled", "false"); 154 addProperty("disabled", "false");
139 addProperty("lastHit", "0"); 155 addProperty("lastHit", "0");
140 addProperty("hitCount", "0"); 156 addProperty("hitCount", "0");
141 } 157 }
142 if (type == "whitelist" || type == "filterlist") 158 if (type == "whitelist" || type == "filterlist")
143 { 159 {
144 addProperty("contentType", 0x7FFFFFFF & ~( 160 addProperty("contentType", 0x7FFFFFFF & ~(
145 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.SNIPPET | t.POPUP | t.GENERICHIDE | 161 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK
146 t.GENERICBLOCK
147 )); 162 ));
148 addProperty("matchCase", "false"); 163 addProperty("matchCase", "false");
149 addProperty("thirdParty", "null"); 164 addProperty("thirdParty", "null");
150 addProperty("domains", ""); 165 addProperty("domains", "");
151 addProperty("sitekeys", ""); 166 addProperty("sitekeys", "");
152 } 167 }
153 if (type == "filterlist") 168 if (type == "filterlist")
154 { 169 {
155 addProperty("collapse", "null"); 170 addProperty("collapse", "null");
156 addProperty("csp", "null"); 171 addProperty("csp", "null");
172 addProperty("rewrite", "null");
157 } 173 }
158 if (type == "elemhide" || type == "elemhideexception" || 174 if (type == "elemhide" || type == "elemhideexception" ||
159 type == "elemhideemulation") 175 type == "elemhideemulation")
160 { 176 {
161 addProperty("injectionDomain", ""); 177 addProperty("selectorDomains", "");
178 addProperty("domains", "");
179 }
180 if (type == "snippet")
181 {
182 addProperty("scriptDomains", "");
162 addProperty("domains", ""); 183 addProperty("domains", "");
163 } 184 }
164 } 185 }
165 186
166 function compareFilter(test, text, expected, postInit) 187 function compareFilter(test, text, expected, postInit)
167 { 188 {
168 addDefaults(expected); 189 addDefaults(expected);
169 190
170 let filter = Filter.fromText(text); 191 let filter = Filter.fromText(text);
171 if (postInit) 192 if (postInit)
(...skipping 22 matching lines...) Expand all
194 } 215 }
195 216
196 exports.testFilterClassDefinitions = function(test) 217 exports.testFilterClassDefinitions = function(test)
197 { 218 {
198 test.equal(typeof Filter, "function", "typeof Filter"); 219 test.equal(typeof Filter, "function", "typeof Filter");
199 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); 220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter");
200 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); 221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
201 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); 222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
202 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); 223 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
203 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); 224 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
225 test.equal(typeof ContentFilter, "function", "typeof ContentFilter");
204 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); 226 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
205 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); 227 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
206 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); 228 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
207 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); 229 test.equal(typeof ElemHideException, "function", "typeof ElemHideException");
208 test.equal(typeof ElemHideEmulationFilter, "function", 230 test.equal(typeof ElemHideEmulationFilter, "function",
209 "typeof ElemHideEmulationFilter"); 231 "typeof ElemHideEmulationFilter");
232 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter");
210 233
211 test.done(); 234 test.done();
212 }; 235 };
213 236
214 exports.testComments = function(test) 237 exports.testComments = function(test)
215 { 238 {
216 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); 239 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]);
217 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); 240 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]);
218 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); 241 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]);
219 242
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 303 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
281 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 304 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
282 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 305 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
283 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]); 306 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]);
284 307
285 test.done(); 308 test.done();
286 }; 309 };
287 310
288 exports.testFilterOptions = function(test) 311 exports.testFilterOptions = function(test)
289 { 312 {
290 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=foo.com,sitekey=foo", ["type=filterlist", "text=bla$match-case,csp=first csp ,script,other,third-party,domain=foo.com,sitekey=foo", "regexp=bla", "matchCase= true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domain s=FOO.COM", "sitekeys=FOO", "csp=first csp"]); 313 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=FOO.cOm,sitekey=foo", ["type=filterlist", "text=bla$match-case,csp=first csp ,script,other,third-party,domain=FOO.cOm,sitekey=foo", "regexp=bla", "matchCase= true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domain s=foo.com", "sitekeys=FOO", "csp=first csp"]);
291 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bar.com", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~( t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~BAR.COM"]); 314 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bAr.coM", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bAr.coM", "regexp=bla", "contentType=" + (defaultTypes & ~( t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~bar.com"]);
292 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo .com|~foo.bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "c ontentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.COM |FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]); 315 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bAR.foO.Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bAR.foO .Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "c ontentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=bar.com |foo.com|~bar.foo.com|~foo.bar.com", "sitekeys=BAR|FOO"]);
293 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SC RIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.B AR.COM", "sitekeys=BAR|FOO"]); 316 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SC RIPT | t.OTHER), "thirdParty=true", "domains=bar.com|foo.com|~bar.foo.com|~foo.b ar.com", "sitekeys=BAR|FOO"]);
317 compareFilter(test, "||content.server.com/files/*.php$rewrite=$1", ["type=filt erlist", "text=||content.server.com/files/*.php$rewrite=$1", "regexp=^[\\w\\-]+: \\/+(?!\\/)(?:[^\\/]+\\.)?content\\.server\\.com\\/files\\/.*\\.php", "matchCase =false", "rewrite=$1", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.SUBDOCUME NT | t.OBJECT | t.OBJECT_SUBREQUEST))]);
294 318
295 // background and image should be the same for backwards compatibility 319 // background and image should be the same for backwards compatibility
296 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 320 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]);
297 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 321 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]);
298 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 322 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
299 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 323 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
300 324
301 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 325 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
302 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 326 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
303 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 327 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
(...skipping 16 matching lines...) Expand all
320 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); 344 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]);
321 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]); 345 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]);
322 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]); 346 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]);
323 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); 347 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
324 348
325 test.done(); 349 test.done();
326 }; 350 };
327 351
328 exports.testElementHidingRules = function(test) 352 exports.testElementHidingRules = function(test)
329 { 353 {
330 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "code=ddd"]); 354 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
331 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "code=body > div:first-child"]); 355 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
332 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "injectionD omain=foo", "code=ddd", "domains=FOO"]); 356 compareFilter(test, "fOO##ddd", ["type=elemhide", "text=fOO##ddd", "selectorDo mains=foo", "selector=ddd", "domains=foo"]);
333 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "in jectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]); 357 compareFilter(test, "Foo,bAr##ddd", ["type=elemhide", "text=Foo,bAr##ddd", "se lectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]);
334 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", " injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]); 358 compareFilter(test, "foo,~baR##ddd", ["type=elemhide", "text=foo,~baR##ddd", " selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]);
335 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar# #ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]); 359 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar# #ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~baz"]);
336 360
337 test.done(); 361 test.done();
338 }; 362 };
339 363
340 exports.testElementHidingExceptions = function(test) 364 exports.testElementHidingExceptions = function(test)
341 { 365 {
342 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "code= ddd"]); 366 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]);
343 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "code=body > div:first-child"]); 367 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]);
344 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "injectionDomain=foo", "code=ddd", "domains=FOO"]); 368 compareFilter(test, "fOO#@#ddd", ["type=elemhideexception", "text=fOO#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo"]);
345 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar# @#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]); 369 compareFilter(test, "Foo,bAr#@#ddd", ["type=elemhideexception", "text=Foo,bAr# @#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]);
346 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba r#@#ddd", "injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]); 370 compareFilter(test, "foo,~baR#@#ddd", ["type=elemhideexception", "text=foo,~ba R#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]);
347 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"] ); 371 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~b az"]);
348 372
349 test.done(); 373 test.done();
350 }; 374 };
351 375
352 exports.testElemHideEmulationFilters = function(test) 376 exports.testElemHideEmulationFilters = function(test)
353 { 377 {
354 // Check valid domain combinations 378 // Check valid domain combinations
355 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-a bp-properties(abc)", "domains=FOO.COM"]); 379 compareFilter(test, "fOO.cOm#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=fOO.cOm#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector =:-abp-properties(abc)", "domains=foo.com"]);
356 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "injectionDomain=f oo.com", "code=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]); 380 compareFilter(test, "Foo.com,~bAr.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=Foo.com,~bAr.com#?#:-abp-properties(abc)", "selectorDomains=f oo.com", "selector=:-abp-properties(abc)", "domains=foo.com|~bar.com"]);
357 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]); 381 compareFilter(test, "foo.com,~baR#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~baR#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector=:-abp-properties(abc)", "domains=foo.com|~bar"]);
358 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "injectionDomain=b ar.com", "code=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]); 382 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomains=b ar.com", "selector=:-abp-properties(abc)", "domains=bar.com|~foo.com"]);
359 383
360 // Check some special cases 384 // Check some special cases
361 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); 385 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]);
362 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com# ?#abc", "injectionDomain=foo.com", "code=abc", "domains=FOO.COM"]); 386 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com# ?#abc", "selectorDomains=foo.com", "selector=abc", "domains=foo.com"]);
363 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "injectionDomain=foo.com", "code=:-abp-fooba r(abc)", "domains=FOO.COM"]); 387 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "selectorDomains=foo.com", "selector=:-abp-f oobar(abc)", "domains=foo.com"]);
364 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=foo .com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); 388 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=foo .com", "selector=aaa :-abp-properties(abc) bbb", "domains=foo.com"]);
365 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*) )", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag e: url(data:*))", "injectionDomain=foo.com", "code=:-abp-properties(|background- image: url(data:*))", "domains=FOO.COM"]); 389 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*) )", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag e: url(data:*))", "selectorDomains=foo.com", "selector=:-abp-properties(|backgro und-image: url(data:*))", "domains=foo.com"]);
366 390
367 // Check conversion of legacy filters 391 // Check conversion of legacy filters
368 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:- abp-properties(abc)", "domains=FOO.COM"]); 392 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selecto r=:-abp-properties(abc)", "domains=foo.com"]);
369 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex t("foo.com#?#:-abp-properties(abc)")); 393 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex t("foo.com#?#:-abp-properties(abc)"));
370 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "injectionDomain=foo.com", "code =[-abp-properties='abc']", "domains=FOO.COM"]); 394 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=foo.com"]);
371 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat ion", "text=foo.com#?#[-abp-properties='abc']", "injectionDomain=foo.com", "code =[-abp-properties='abc']", "domains=FOO.COM"]); 395 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat ion", "text=foo.com#?#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=foo.com"]);
372 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=fo o.com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); 396 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=fo o.com", "selector=aaa :-abp-properties(abc) bbb", "domains=foo.com"]);
373 397
374 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) . 398 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) .
375 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "injectionDomain=foo.com", "cod e=[-abp-properties-bogus='abc']", "domains=FOO.COM"]); 399 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomains=foo.com", "sel ector=[-abp-properties-bogus='abc']", "domains=foo.com"]);
376 400
377 test.done(); 401 test.done();
378 }; 402 };
379 403
380 exports.testEmptyElemHideDomains = function(test) 404 exports.testEmptyElemHideDomains = function(test)
381 { 405 {
382 let emptyDomainFilters = [ 406 let emptyDomainFilters = [
383 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", 407 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector",
384 ",foo.com##selector", "foo.com,~##selector", 408 ",foo.com##selector", "foo.com,~##selector",
385 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" 409 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector"
386 ]; 410 ];
387 411
388 for (let filterText of emptyDomainFilters) 412 for (let filterText of emptyDomainFilters)
389 { 413 {
390 let filter = Filter.fromText(filterText); 414 let filter = Filter.fromText(filterText);
391 test.ok(filter instanceof InvalidFilter); 415 test.ok(filter instanceof InvalidFilter);
392 test.equal(filter.reason, "filter_invalid_domain"); 416 test.equal(filter.reason, "filter_invalid_domain");
393 } 417 }
394 418
395 test.done(); 419 test.done();
396 }; 420 };
397 421
398 exports.testElemHideRulesWithBraces = function(test) 422 exports.testElemHideRulesWithBraces = function(test)
399 { 423 {
400 compareFilter( 424 compareFilter(
401 test, "###foo{color: red}", [ 425 test, "###foo{color: red}", [
402 "type=elemhide", 426 "type=elemhide",
403 "text=###foo{color: red}", 427 "text=###foo{color: red}",
404 "injectionDomain=", 428 "selectorDomains=",
405 "code=#foo\\7B color: red\\7D ", 429 "selector=#foo\\7B color: red\\7D ",
406 "domains=" 430 "domains="
407 ] 431 ]
408 ); 432 );
409 compareFilter( 433 compareFilter(
410 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ 434 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [
411 "type=elemhideemulation", 435 "type=elemhideemulation",
412 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", 436 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
413 "injectionDomain=foo.com", 437 "selectorDomains=foo.com",
414 "code=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", 438 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)",
415 "domains=FOO.COM" 439 "domains=foo.com"
416 ] 440 ]
417 ); 441 );
442 test.done();
443 };
444
445 exports.testSnippetFilters = function(test)
446 {
447 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "s criptDomains=foo.com", "script=abc", "domains=foo.com"]);
448 compareFilter(test, "foo.com,~bar.com#$#abc", ["type=snippet", "text=foo.com,~ bar.com#$#abc", "scriptDomains=foo.com", "script=abc", "domains=foo.com|~bar.com "]);
449 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar# $#abc", "scriptDomains=foo.com", "script=abc", "domains=foo.com|~bar"]);
450 compareFilter(test, "~foo.com,bar.com#$#abc", ["type=snippet", "text=~foo.com, bar.com#$#abc", "scriptDomains=bar.com", "script=abc", "domains=bar.com|~foo.com "]);
451
418 test.done(); 452 test.done();
419 }; 453 };
420 454
421 exports.testFilterNormalization = function(test) 455 exports.testFilterNormalization = function(test)
422 { 456 {
423 // Line breaks etc 457 // Line breaks etc
424 test.equal(Filter.normalize("\n\t\nad\ns"), 458 test.equal(Filter.normalize("\n\t\nad\ns"),
425 "ads"); 459 "ads");
426 460
427 // Comment filters 461 // Comment filters
(...skipping 22 matching lines...) Expand all
450 test.equal(Filter.normalize(" domain.c om#@# # sele ctor "), 484 test.equal(Filter.normalize(" domain.c om#@# # sele ctor "),
451 "domain.com#@## sele ctor"); 485 "domain.com#@## sele ctor");
452 486
453 // Incorrect syntax: the separator "#@#" cannot contain spaces; treated as a 487 // Incorrect syntax: the separator "#@#" cannot contain spaces; treated as a
454 // regular filter instead (not an element hiding filter either!), because 488 // regular filter instead (not an element hiding filter either!), because
455 // unlike the case with "# ?##" the "##" following the "@" is not considered 489 // unlike the case with "# ?##" the "##" following the "@" is not considered
456 // to be a separator 490 // to be a separator
457 test.equal(Filter.normalize(" domain.c om# @## sele ctor "), 491 test.equal(Filter.normalize(" domain.c om# @## sele ctor "),
458 "domain.com#@##selector"); 492 "domain.com#@##selector");
459 493
494 // Snippet filters
495 test.equal(Filter.normalize(" domain.c om#$# sni pp et "),
496 "domain.com#$#sni pp et");
497
460 // Regular filters 498 // Regular filters
461 let normalized = Filter.normalize( 499 let normalized = Filter.normalize(
462 " b$l a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p " 500 " b$l a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p "
463 ); 501 );
464 test.equal( 502 test.equal(
465 normalized, 503 normalized,
466 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" 504 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p"
467 ); 505 );
468 compareFilter( 506 compareFilter(
469 test, normalized, [ 507 test, normalized, [
470 "type=filterlist", 508 "type=filterlist",
471 "text=" + normalized, 509 "text=" + normalized,
472 "csp=c s p", 510 "csp=c s p",
473 "domains=DOMAIN.COM|FOO.COM", 511 "domains=domain.com|foo.com",
474 "sitekeys=FOO", 512 "sitekeys=FOO",
475 "regexp=b\\$la", 513 "regexp=b\\$la",
476 "contentType=" + t.CSP 514 "contentType=" + t.CSP
477 ] 515 ]
478 ); 516 );
479 517
480 // Some $csp edge cases 518 // Some $csp edge cases
481 test.equal(Filter.normalize("$csp= c s p"), 519 test.equal(Filter.normalize("$csp= c s p"),
482 "$csp=c s p"); 520 "$csp=c s p");
483 test.equal(Filter.normalize("$$csp= c s p"), 521 test.equal(Filter.normalize("$$csp= c s p"),
484 "$$csp=c s p"); 522 "$$csp=c s p");
485 test.equal(Filter.normalize("$$$csp= c s p"), 523 test.equal(Filter.normalize("$$$csp= c s p"),
486 "$$$csp=c s p"); 524 "$$$csp=c s p");
487 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), 525 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"),
488 "foo?csp=bar$csp=script-src 'self'"); 526 "foo?csp=bar$csp=script-src 'self'");
489 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), 527 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"),
490 "foo$bar=csp=baz,csp=script-src 'self'"); 528 "foo$bar=csp=baz,csp=script-src 'self'");
491 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"), 529 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"),
492 "foo$csp=c s p csp= ba z,csp=script-src 'self'"); 530 "foo$csp=c s p csp= ba z,csp=script-src 'self'");
493 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"), 531 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"),
494 "foo$csp=bar,$csp=c s p"); 532 "foo$csp=bar,$csp=c s p");
495 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), 533 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"),
496 "foo$bar$csp=ba r"); 534 "foo$bar$csp=ba r");
497 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), 535 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "),
498 "f$o$o$csp=f o o"); 536 "f$o$o$csp=f o o");
499 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"), 537 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"),
500 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); 538 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3");
501 539 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"),
502 test.done(); 540 "||content.server.com/files/*.php$rewrite=$1");
503 }; 541 test.done();
542 };
543
544
545 exports.testFilterRewriteOption = function(test)
546 {
547 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1";
548
549 let filter = Filter.fromText(text);
550
551 test.equal(filter.rewrite, "$1");
552 // no rewrite occured: didn't match.
553 test.equal(filter.rewriteUrl("foo"), "foo");
554 // rewrite occured: matched.
555 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"),
556 "http://content.server/file/foo.txt");
557
558 // checking for same origin.
559 let rewriteDiffOrigin =
560 "/content\\.server(\\/file\\/.*\\.txt)\\?.*$/$rewrite=foo.com$1";
561 let filterDiffOrigin = Filter.fromText(rewriteDiffOrigin);
562
563 // no rewrite occured because of a different origin.
564 test.equal(
565 filterDiffOrigin.rewriteUrl("http://content.server/file/foo.txt?bar"),
566 "http://content.server/file/foo.txt?bar"
567 );
568
569 // relative path.
570 let rewriteRelative = "/(\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1/disable";
571 let filterRelative = Filter.fromText(rewriteRelative);
572
573 test.equal(
574 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"),
575 "http://content.server/file/foo.txt/disable"
576 );
577 test.equal(
578 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"),
579 "http://example.com/file/foo.txt/disable"
580 );
581
582 // Example from https://github.com/uBlockOrigin/uBlock-issues/issues/46#issuec omment-391190533
583 // The rewrite shouldn't happen.
584 let rewriteEvil = "/(^https?:\\/\\/[^/])/$script,rewrite=$1.evil.com";
585 let filterEvil = Filter.fromText(rewriteEvil);
586
587 test.equal(
588 filterEvil.rewriteUrl("https://www.adblockplus.org/script.js"),
589 "https://www.adblockplus.org/script.js"
590 );
591
592 test.done();
593 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld