OLD | NEW |
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 |
(...skipping 26 matching lines...) Expand all Loading... |
37 exports.setUp = function(callback) | 37 exports.setUp = function(callback) |
38 { | 38 { |
39 let sandboxedRequire = createSandbox(); | 39 let sandboxedRequire = createSandbox(); |
40 ( | 40 ( |
41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, | 41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, |
42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, | 42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, |
43 ElemHideException, | 43 ElemHideException, |
44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") | 44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") |
45 ); | 45 ); |
46 t = RegExpFilter.typeMap; | 46 t = RegExpFilter.typeMap; |
47 defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | | 47 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
48 t.GENERICHIDE | t.GENERICBLOCK); | 48 t.GENERICHIDE | t.GENERICBLOCK); |
49 | 49 |
50 callback(); | 50 callback(); |
51 }; | 51 }; |
52 | 52 |
53 function serializeFilter(filter) | 53 function serializeFilter(filter) |
54 { | 54 { |
55 // Filter serialization only writes out essential properties, need to do a ful
l serialization here | 55 // Filter serialization only writes out essential properties, need to do a ful
l serialization here |
56 let result = []; | 56 let result = []; |
57 result.push("text=" + filter.text); | 57 result.push("text=" + filter.text); |
(...skipping 28 matching lines...) Expand all Loading... |
86 result.push("matchCase=" + filter.matchCase); | 86 result.push("matchCase=" + filter.matchCase); |
87 | 87 |
88 let sitekeys = filter.sitekeys || []; | 88 let sitekeys = filter.sitekeys || []; |
89 result.push("sitekeys=" + sitekeys.slice().sort().join("|")); | 89 result.push("sitekeys=" + sitekeys.slice().sort().join("|")); |
90 | 90 |
91 result.push("thirdParty=" + filter.thirdParty); | 91 result.push("thirdParty=" + filter.thirdParty); |
92 if (filter instanceof BlockingFilter) | 92 if (filter instanceof BlockingFilter) |
93 { | 93 { |
94 result.push("type=filterlist"); | 94 result.push("type=filterlist"); |
95 result.push("collapse=" + filter.collapse); | 95 result.push("collapse=" + filter.collapse); |
| 96 result.push("csp=" + filter.csp); |
96 } | 97 } |
97 else if (filter instanceof WhitelistFilter) | 98 else if (filter instanceof WhitelistFilter) |
98 result.push("type=whitelist"); | 99 result.push("type=whitelist"); |
99 } | 100 } |
100 else if (filter instanceof ElemHideBase) | 101 else if (filter instanceof ElemHideBase) |
101 { | 102 { |
102 if (filter instanceof ElemHideFilter) | 103 if (filter instanceof ElemHideFilter) |
103 result.push("type=elemhide"); | 104 result.push("type=elemhide"); |
104 else if (filter instanceof ElemHideException) | 105 else if (filter instanceof ElemHideException) |
105 result.push("type=elemhideexception"); | 106 result.push("type=elemhideexception"); |
(...skipping 28 matching lines...) Expand all Loading... |
134 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || | 135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || |
135 type == "elemhideexception" || type == "elemhideemulation") | 136 type == "elemhideexception" || type == "elemhideemulation") |
136 { | 137 { |
137 addProperty("disabled", "false"); | 138 addProperty("disabled", "false"); |
138 addProperty("lastHit", "0"); | 139 addProperty("lastHit", "0"); |
139 addProperty("hitCount", "0"); | 140 addProperty("hitCount", "0"); |
140 } | 141 } |
141 if (type == "whitelist" || type == "filterlist") | 142 if (type == "whitelist" || type == "filterlist") |
142 { | 143 { |
143 addProperty("contentType", 0x7FFFFFFF & ~( | 144 addProperty("contentType", 0x7FFFFFFF & ~( |
144 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | | 145 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK |
145 RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE | | |
146 RegExpFilter.typeMap.GENERICBLOCK | |
147 )); | 146 )); |
148 addProperty("matchCase", "false"); | 147 addProperty("matchCase", "false"); |
149 addProperty("thirdParty", "null"); | 148 addProperty("thirdParty", "null"); |
150 addProperty("domains", ""); | 149 addProperty("domains", ""); |
151 addProperty("sitekeys", ""); | 150 addProperty("sitekeys", ""); |
152 } | 151 } |
153 if (type == "filterlist") | 152 if (type == "filterlist") |
| 153 { |
154 addProperty("collapse", "null"); | 154 addProperty("collapse", "null"); |
| 155 addProperty("csp", "null"); |
| 156 } |
155 if (type == "elemhide" || type == "elemhideexception" || | 157 if (type == "elemhide" || type == "elemhideexception" || |
156 type == "elemhideemulation") | 158 type == "elemhideemulation") |
157 { | 159 { |
158 addProperty("selectorDomain", ""); | 160 addProperty("selectorDomain", ""); |
159 addProperty("domains", ""); | 161 addProperty("domains", ""); |
160 } | 162 } |
161 } | 163 } |
162 | 164 |
163 function compareFilter(test, text, expected, postInit) | 165 function compareFilter(test, text, expected, postInit) |
164 { | 166 { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); | 279 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); |
278 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); | 280 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); |
279 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); | 281 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); |
280 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&
()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp
es]); | 282 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&
()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp
es]); |
281 | 283 |
282 test.done(); | 284 test.done(); |
283 }; | 285 }; |
284 | 286 |
285 exports.testFilterOptions = function(test) | 287 exports.testFilterOptions = function(test) |
286 { | 288 { |
287 compareFilter(test, "bla$match-case,script,other,third-party,domain=foo.com,si
tekey=foo", ["type=filterlist", "text=bla$match-case,script,other,third-party,do
main=foo.com,sitekey=foo", "regexp=bla", "matchCase=true", "contentType=" + (t.S
CRIPT | t.OTHER), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO"]); | 289 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom
ain=foo.com,sitekey=foo,csp=second csp", ["type=filterlist", "text=bla$match-cas
e,csp=first csp,script,other,third-party,domain=foo.com,sitekey=foo,csp=second c
sp", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CS
P), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO", "csp=first csp; second
csp"]); |
288 compareFilter(test, "bla$~match-case,~script,~other,~third-party,domain=~bar.c
om", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domai
n=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER
)), "thirdParty=false", "domains=~BAR.COM"]); | 290 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"]); |
| 291 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"]); |
289 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"]); | 292 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"]); |
290 | 293 |
291 // background and image should be the same for backwards compatibility | 294 // background and image should be the same for backwards compatibility |
292 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); | 295 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); |
293 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); | 296 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); |
294 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 297 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
295 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 298 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
296 | 299 |
297 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); | 300 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); |
298 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 301 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); |
299 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 302 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); |
300 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text=
@@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); | 303 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text=
@@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); |
301 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text
=@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes &
~(t.SCRIPT | t.OTHER))]); | 304 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text
=@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes &
~(t.SCRIPT | t.OTHER))]); |
302 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document"
, "regexp=bla", "contentType=" + t.DOCUMENT]); | 305 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document"
, "regexp=bla", "contentType=" + t.DOCUMENT]); |
303 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text=
@@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.ELEMHIDE)]); | 306 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text=
@@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.ELEMHIDE)]); |
304 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text
=@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes &
~(t.SCRIPT | t.OTHER))]); | 307 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text
=@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes &
~(t.SCRIPT | t.OTHER))]); |
305 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide"
, "regexp=bla", "contentType=" + t.ELEMHIDE]); | 308 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide"
, "regexp=bla", "contentType=" + t.ELEMHIDE]); |
306 | 309 |
307 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text=
@@bla$~script,~other,donottrack", "reason=filter_unknown_option"]); | 310 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text=
@@bla$~script,~other,donottrack", "reason=filter_unknown_option"]); |
308 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text
=@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]); | 311 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text
=@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]); |
309 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac
k", "reason=filter_unknown_option"]); | 312 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac
k", "reason=filter_unknown_option"]); |
310 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea
son=filter_unknown_option"]); | 313 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea
son=filter_unknown_option"]); |
311 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f
oobar", "reason=filter_unknown_option"]); | 314 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f
oobar", "reason=filter_unknown_option"]); |
312 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar,
image", "reason=filter_unknown_option"]); | 315 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar,
image", "reason=filter_unknown_option"]); |
313 | 316 |
| 317 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor
t-uri", "reason=filter_invalid_csp"]); |
| 318 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs
p=foo,csp=report-to", "reason=filter_invalid_csp"]); |
| 319 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla
$csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); |
| 320 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp
=foo,csp=base-uri", "reason=filter_invalid_csp"]); |
| 321 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali
d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp
"]); |
| 322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); |
| 323 |
314 test.done(); | 324 test.done(); |
315 }; | 325 }; |
316 | 326 |
317 exports.testElementHidingRules = function(test) | 327 exports.testElementHidingRules = function(test) |
318 { | 328 { |
319 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); | 329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); |
320 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); | 330 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); |
321 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo
main=foo", "selector=ddd", "domains=FOO"]); | 331 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo
main=foo", "selector=ddd", "domains=FOO"]); |
322 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se
lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 332 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se
lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); |
323 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); | 333 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ | 409 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ |
400 "type=elemhideemulation", | 410 "type=elemhideemulation", |
401 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", | 411 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", |
402 "selectorDomain=foo.com", | 412 "selectorDomain=foo.com", |
403 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 413 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", |
404 "domains=FOO.COM" | 414 "domains=FOO.COM" |
405 ] | 415 ] |
406 ); | 416 ); |
407 test.done(); | 417 test.done(); |
408 }; | 418 }; |
| 419 |
| 420 exports.testFilterNormalization = function(test) |
| 421 { |
| 422 // Line breaks etc |
| 423 test.equal(Filter.normalize("\n\t\nad\ns"), |
| 424 "ads"); |
| 425 |
| 426 // Comment filters |
| 427 test.equal(Filter.normalize(" ! fo o## bar "), |
| 428 "! fo o## bar"); |
| 429 |
| 430 // Element hiding filters |
| 431 test.equal(Filter.normalize(" domain.c om## # sele ctor "), |
| 432 "domain.com### sele ctor"); |
| 433 |
| 434 // Regular filters |
| 435 let normalized = Filter.normalize( |
| 436 " b$l a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p
" |
| 437 ); |
| 438 test.equal( |
| 439 normalized, |
| 440 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" |
| 441 ); |
| 442 compareFilter( |
| 443 test, normalized, [ |
| 444 "type=filterlist", |
| 445 "text=" + normalized, |
| 446 "csp=c s p", |
| 447 "domains=DOMAIN.COM|FOO.COM", |
| 448 "sitekeys=FOO", |
| 449 "regexp=b\\$la", |
| 450 "contentType=" + t.CSP |
| 451 ] |
| 452 ); |
| 453 |
| 454 // Some $csp edge cases |
| 455 test.equal(Filter.normalize("$csp= c s p"), |
| 456 "$csp=c s p"); |
| 457 test.equal(Filter.normalize("$$csp= c s p"), |
| 458 "$$csp=c s p"); |
| 459 test.equal(Filter.normalize("$$$csp= c s p"), |
| 460 "$$$csp=c s p"); |
| 461 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), |
| 462 "foo?csp=bar$csp=script-src 'self'"); |
| 463 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), |
| 464 "foo$bar=csp=baz,csp=script-src 'self'"); |
| 465 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self
'"), |
| 466 "foo$csp=c s p csp= ba z,csp=script-src 'self'"); |
| 467 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"), |
| 468 "foo$csp=bar,$csp=c s p"); |
| 469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), |
| 470 "foo$bar$csp=ba r"); |
| 471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), |
| 472 "f$o$o$csp=f o o"); |
| 473 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), |
| 474 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); |
| 475 |
| 476 test.done(); |
| 477 }; |
OLD | NEW |