LEFT | RIGHT |
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 ScriptFilter = null; | 28 let ContentFilter = null; |
29 let WhitelistFilter = null; | 29 let WhitelistFilter = null; |
30 let ElemHideBase = null; | 30 let ElemHideBase = null; |
31 let ElemHideFilter = null; | 31 let ElemHideFilter = null; |
32 let ElemHideException = null; | 32 let ElemHideException = null; |
33 let ElemHideEmulationFilter = null; | 33 let ElemHideEmulationFilter = null; |
34 let SnippetFilter = null; | 34 let SnippetFilter = null; |
35 | 35 |
36 let t = null; | 36 let t = null; |
37 let defaultTypes = null; | 37 let defaultTypes = null; |
38 | 38 |
39 exports.setUp = function(callback) | 39 exports.setUp = function(callback) |
40 { | 40 { |
41 let sandboxedRequire = createSandbox(); | 41 let sandboxedRequire = createSandbox(); |
42 ( | 42 ( |
43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, | 43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, |
44 BlockingFilter, WhitelistFilter, ScriptFilter, ElemHideBase, | 44 BlockingFilter, WhitelistFilter, ContentFilter, ElemHideBase, |
45 ElemHideFilter, ElemHideException, ElemHideEmulationFilter, | 45 ElemHideFilter, ElemHideException, ElemHideEmulationFilter, |
46 SnippetFilter} = sandboxedRequire("../lib/filterClasses") | 46 SnippetFilter} = sandboxedRequire("../lib/filterClasses") |
47 ); | 47 ); |
48 t = RegExpFilter.typeMap; | 48 t = RegExpFilter.typeMap; |
49 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | | 49 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
50 t.GENERICHIDE | t.GENERICBLOCK); | 50 t.GENERICHIDE | t.GENERICBLOCK); |
51 | 51 |
52 callback(); | 52 callback(); |
53 }; | 53 }; |
54 | 54 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 else if (filter instanceof ElemHideBase) | 104 else if (filter instanceof ElemHideBase) |
105 { | 105 { |
106 if (filter instanceof ElemHideFilter) | 106 if (filter instanceof ElemHideFilter) |
107 result.push("type=elemhide"); | 107 result.push("type=elemhide"); |
108 else if (filter instanceof ElemHideException) | 108 else if (filter instanceof ElemHideException) |
109 result.push("type=elemhideexception"); | 109 result.push("type=elemhideexception"); |
110 else if (filter instanceof ElemHideEmulationFilter) | 110 else if (filter instanceof ElemHideEmulationFilter) |
111 result.push("type=elemhideemulation"); | 111 result.push("type=elemhideemulation"); |
112 | 112 |
113 result.push("selectorDomains=" + (filter.selectorDomains || "")); | 113 result.push("selectorDomains=" + |
| 114 [...filter.domains || []] |
| 115 .filter(([domain, isIncluded]) => isIncluded) |
| 116 .map(([domain]) => domain.toLowerCase())); |
114 result.push("selector=" + filter.selector); | 117 result.push("selector=" + filter.selector); |
115 } | 118 } |
116 else if (filter instanceof SnippetFilter) | 119 else if (filter instanceof SnippetFilter) |
117 { | 120 { |
118 result.push("type=snippet"); | 121 result.push("type=snippet"); |
119 result.push("scriptDomains=" + (filter.scriptDomains || "")); | 122 result.push("scriptDomains=" + |
| 123 [...filter.domains || []] |
| 124 .filter(([domain, isIncluded]) => isIncluded) |
| 125 .map(([domain]) => domain.toLowerCase())); |
120 result.push("script=" + filter.script); | 126 result.push("script=" + filter.script); |
121 } | 127 } |
122 } | 128 } |
123 return result; | 129 return result; |
124 } | 130 } |
125 | 131 |
126 function addDefaults(expected) | 132 function addDefaults(expected) |
127 { | 133 { |
128 let type = null; | 134 let type = null; |
129 let hasProperty = {}; | 135 let hasProperty = {}; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 215 } |
210 | 216 |
211 exports.testFilterClassDefinitions = function(test) | 217 exports.testFilterClassDefinitions = function(test) |
212 { | 218 { |
213 test.equal(typeof Filter, "function", "typeof Filter"); | 219 test.equal(typeof Filter, "function", "typeof Filter"); |
214 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); | 220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); |
215 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); | 221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); |
216 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); | 222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); |
217 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); | 223 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); |
218 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); | 224 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); |
219 test.equal(typeof ScriptFilter, "function", "typeof ScriptFilter"); | 225 test.equal(typeof ContentFilter, "function", "typeof ContentFilter"); |
220 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); | 226 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); |
221 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); | 227 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); |
222 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); | 228 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); |
223 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); | 229 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); |
224 test.equal(typeof ElemHideEmulationFilter, "function", | 230 test.equal(typeof ElemHideEmulationFilter, "function", |
225 "typeof ElemHideEmulationFilter"); | 231 "typeof ElemHideEmulationFilter"); |
226 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter"); | 232 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter"); |
227 | 233 |
228 test.done(); | 234 test.done(); |
229 }; | 235 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 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]); |
298 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]); |
299 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]); |
300 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]); |
301 | 307 |
302 test.done(); | 308 test.done(); |
303 }; | 309 }; |
304 | 310 |
305 exports.testFilterOptions = function(test) | 311 exports.testFilterOptions = function(test) |
306 { | 312 { |
307 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"]); |
308 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"]); |
309 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"]); |
310 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"]); |
311 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"]); | 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))]); |
312 | 318 |
313 // background and image should be the same for backwards compatibility | 319 // background and image should be the same for backwards compatibility |
314 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)]); |
315 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)]); |
316 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)]); |
317 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)]); |
318 | 324 |
319 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))]); |
320 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))]); |
321 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 18 matching lines...) Expand all Loading... |
340 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
"]); |
341 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"]); |
342 | 348 |
343 test.done(); | 349 test.done(); |
344 }; | 350 }; |
345 | 351 |
346 exports.testElementHidingRules = function(test) | 352 exports.testElementHidingRules = function(test) |
347 { | 353 { |
348 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); | 354 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); |
349 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); | 355 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); |
350 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo
mains=foo", "selector=ddd", "domains=FOO"]); | 356 compareFilter(test, "fOO##ddd", ["type=elemhide", "text=fOO##ddd", "selectorDo
mains=foo", "selector=ddd", "domains=foo"]); |
351 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se
lectorDomains=foo,bar", "selector=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"]); |
352 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); | 358 compareFilter(test, "foo,~baR##ddd", ["type=elemhide", "text=foo,~baR##ddd", "
selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]); |
353 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "selectorDomains=foo,bar", "selector=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"]); |
354 | 360 |
355 test.done(); | 361 test.done(); |
356 }; | 362 }; |
357 | 363 |
358 exports.testElementHidingExceptions = function(test) | 364 exports.testElementHidingExceptions = function(test) |
359 { | 365 { |
360 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); | 366 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); |
361 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "selector=body > div:first-child"]); | 367 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "selector=body > div:first-child"]); |
362 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd",
"selectorDomains=foo", "selector=ddd", "domains=FOO"]); | 368 compareFilter(test, "fOO#@#ddd", ["type=elemhideexception", "text=fOO#@#ddd",
"selectorDomains=foo", "selector=ddd", "domains=foo"]); |
363 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#
@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 369 compareFilter(test, "Foo,bAr#@#ddd", ["type=elemhideexception", "text=Foo,bAr#
@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]); |
364 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba
r#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); | 370 compareFilter(test, "foo,~baR#@#ddd", ["type=elemhideexception", "text=foo,~ba
R#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]); |
365 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~B
AZ"]); | 371 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~b
az"]); |
366 | 372 |
367 test.done(); | 373 test.done(); |
368 }; | 374 }; |
369 | 375 |
370 exports.testElemHideEmulationFilters = function(test) | 376 exports.testElemHideEmulationFilters = function(test) |
371 { | 377 { |
372 // Check valid domain combinations | 378 // Check valid domain combinations |
373 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"]); | 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"]); |
374 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"]); | 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"]); |
375 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"]); | 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"]); |
376 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"]); | 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"]); |
377 | 383 |
378 // Check some special cases | 384 // Check some special cases |
379 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"]); |
380 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "selectorDomains=foo.com", "selector=abc", "domains=FOO.COM"]); | 386 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "selectorDomains=foo.com", "selector=abc", "domains=foo.com"]); |
381 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"]); | 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"]); |
382 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"]); | 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"]); |
383 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"]); | 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"]); |
384 | 390 |
385 // Check conversion of legacy filters | 391 // Check conversion of legacy filters |
386 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"]); | 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"]); |
387 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)")); |
388 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"]); | 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"]); |
389 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"]); | 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"]); |
390 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"]); | 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"]); |
391 | 397 |
392 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. | 398 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. |
393 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"]); | 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"]); |
394 | 400 |
395 test.done(); | 401 test.done(); |
396 }; | 402 }; |
397 | 403 |
398 exports.testEmptyElemHideDomains = function(test) | 404 exports.testEmptyElemHideDomains = function(test) |
399 { | 405 { |
400 let emptyDomainFilters = [ | 406 let emptyDomainFilters = [ |
401 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", | 407 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |
402 ",foo.com##selector", "foo.com,~##selector", | 408 ",foo.com##selector", "foo.com,~##selector", |
403 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" | 409 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" |
(...skipping 19 matching lines...) Expand all Loading... |
423 "selector=#foo\\7B color: red\\7D ", | 429 "selector=#foo\\7B color: red\\7D ", |
424 "domains=" | 430 "domains=" |
425 ] | 431 ] |
426 ); | 432 ); |
427 compareFilter( | 433 compareFilter( |
428 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ | 434 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ |
429 "type=elemhideemulation", | 435 "type=elemhideemulation", |
430 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", | 436 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", |
431 "selectorDomains=foo.com", | 437 "selectorDomains=foo.com", |
432 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 438 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", |
433 "domains=FOO.COM" | 439 "domains=foo.com" |
434 ] | 440 ] |
435 ); | 441 ); |
436 test.done(); | 442 test.done(); |
437 }; | 443 }; |
438 | 444 |
439 exports.testSnippetFilters = function(test) | 445 exports.testSnippetFilters = function(test) |
440 { | 446 { |
441 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "s
criptDomains=foo.com", "script=abc", "domains=FOO.COM"]); | 447 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "s
criptDomains=foo.com", "script=abc", "domains=foo.com"]); |
442 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
"]); | 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
"]); |
443 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar#
$#abc", "scriptDomains=foo.com", "script=abc", "domains=FOO.COM|~BAR"]); | 449 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar#
$#abc", "scriptDomains=foo.com", "script=abc", "domains=foo.com|~bar"]); |
444 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
"]); | 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
"]); |
445 | 451 |
446 test.done(); | 452 test.done(); |
447 }; | 453 }; |
448 | 454 |
449 exports.testFilterNormalization = function(test) | 455 exports.testFilterNormalization = function(test) |
450 { | 456 { |
451 // Line breaks etc | 457 // Line breaks etc |
452 test.equal(Filter.normalize("\n\t\nad\ns"), | 458 test.equal(Filter.normalize("\n\t\nad\ns"), |
453 "ads"); | 459 "ads"); |
454 | 460 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 ); | 501 ); |
496 test.equal( | 502 test.equal( |
497 normalized, | 503 normalized, |
498 "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" |
499 ); | 505 ); |
500 compareFilter( | 506 compareFilter( |
501 test, normalized, [ | 507 test, normalized, [ |
502 "type=filterlist", | 508 "type=filterlist", |
503 "text=" + normalized, | 509 "text=" + normalized, |
504 "csp=c s p", | 510 "csp=c s p", |
505 "domains=DOMAIN.COM|FOO.COM", | 511 "domains=domain.com|foo.com", |
506 "sitekeys=FOO", | 512 "sitekeys=FOO", |
507 "regexp=b\\$la", | 513 "regexp=b\\$la", |
508 "contentType=" + t.CSP | 514 "contentType=" + t.CSP |
509 ] | 515 ] |
510 ); | 516 ); |
511 | 517 |
512 // Some $csp edge cases | 518 // Some $csp edge cases |
513 test.equal(Filter.normalize("$csp= c s p"), | 519 test.equal(Filter.normalize("$csp= c s p"), |
514 "$csp=c s p"); | 520 "$csp=c s p"); |
515 test.equal(Filter.normalize("$$csp= c s p"), | 521 test.equal(Filter.normalize("$$csp= c s p"), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 572 |
567 test.equal( | 573 test.equal( |
568 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), | 574 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), |
569 "http://content.server/file/foo.txt/disable" | 575 "http://content.server/file/foo.txt/disable" |
570 ); | 576 ); |
571 test.equal( | 577 test.equal( |
572 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), | 578 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), |
573 "http://example.com/file/foo.txt/disable" | 579 "http://example.com/file/foo.txt/disable" |
574 ); | 580 ); |
575 | 581 |
576 test.done(); | 582 // Example from https://github.com/uBlockOrigin/uBlock-issues/issues/46#issuec
omment-391190533 |
577 }; | 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 }; |
LEFT | RIGHT |