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 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); | 284 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); |
285 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); | 285 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); |
286 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); | 286 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); |
287 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&
()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp
es]); | 287 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&
()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp
es]); |
288 | 288 |
289 test.done(); | 289 test.done(); |
290 }; | 290 }; |
291 | 291 |
292 exports.testFilterOptions = function(test) | 292 exports.testFilterOptions = function(test) |
293 { | 293 { |
294 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"]); | 294 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"]); |
295 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"]); | 295 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"]); |
296 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"]); | 296 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"]); |
297 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"]); | 297 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"]); |
298 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))]); | 298 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))]); |
299 | |
300 // Blank values for domain, sitekey, and csp should be ignored. | |
301 compareFilter(test, "bla$match-case,csp=,script,other,third-party,domain=,site
key=", ["type=filterlist", "text=bla$match-case,csp=,script,other,third-party,do
main=,sitekey=", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.
OTHER | t.CSP), "thirdParty=true"]); | |
302 | 299 |
303 // background and image should be the same for backwards compatibility | 300 // background and image should be the same for backwards compatibility |
304 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); | 301 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); |
305 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); | 302 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); |
306 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 303 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
307 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 304 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
308 | 305 |
309 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); | 306 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); |
310 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 307 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); |
311 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 308 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... |
330 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali
d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp
"]); | 327 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali
d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp
"]); |
331 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); | 328 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); |
332 | 329 |
333 test.done(); | 330 test.done(); |
334 }; | 331 }; |
335 | 332 |
336 exports.testElementHidingRules = function(test) | 333 exports.testElementHidingRules = function(test) |
337 { | 334 { |
338 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); | 335 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); |
339 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); | 336 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); |
340 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo
mains=foo", "selector=ddd", "domains=FOO"]); | 337 compareFilter(test, "fOO##ddd", ["type=elemhide", "text=fOO##ddd", "selectorDo
mains=foo", "selector=ddd", "domains=foo"]); |
341 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se
lectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 338 compareFilter(test, "Foo,bAr##ddd", ["type=elemhide", "text=Foo,bAr##ddd", "se
lectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]); |
342 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); | 339 compareFilter(test, "foo,~baR##ddd", ["type=elemhide", "text=foo,~baR##ddd", "
selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]); |
343 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); | 340 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~baz"]); |
344 | 341 |
345 test.done(); | 342 test.done(); |
346 }; | 343 }; |
347 | 344 |
348 exports.testElementHidingExceptions = function(test) | 345 exports.testElementHidingExceptions = function(test) |
349 { | 346 { |
350 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); | 347 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); |
351 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "selector=body > div:first-child"]); | 348 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "selector=body > div:first-child"]); |
352 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd",
"selectorDomains=foo", "selector=ddd", "domains=FOO"]); | 349 compareFilter(test, "fOO#@#ddd", ["type=elemhideexception", "text=fOO#@#ddd",
"selectorDomains=foo", "selector=ddd", "domains=foo"]); |
353 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#
@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 350 compareFilter(test, "Foo,bAr#@#ddd", ["type=elemhideexception", "text=Foo,bAr#
@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]); |
354 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba
r#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); | 351 compareFilter(test, "foo,~baR#@#ddd", ["type=elemhideexception", "text=foo,~ba
R#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]); |
355 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~B
AZ"]); | 352 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~b
az"]); |
356 | 353 |
357 test.done(); | 354 test.done(); |
358 }; | 355 }; |
359 | 356 |
360 exports.testElemHideEmulationFilters = function(test) | 357 exports.testElemHideEmulationFilters = function(test) |
361 { | 358 { |
362 // Check valid domain combinations | 359 // Check valid domain combinations |
363 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"]); | 360 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"]); |
364 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"]); | 361 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"]); |
365 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"]); | 362 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"]); |
366 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"]); | 363 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"]); |
367 | 364 |
368 // Check some special cases | 365 // Check some special cases |
369 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab
p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); | 366 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab
p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); |
370 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "selectorDomains=foo.com", "selector=abc", "domains=FOO.COM"]); | 367 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "selectorDomains=foo.com", "selector=abc", "domains=foo.com"]); |
371 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"]); | 368 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"]); |
372 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"]); | 369 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"]); |
373 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"]); | 370 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"]); |
374 | 371 |
375 // Check conversion of legacy filters | 372 // Check conversion of legacy filters |
376 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"]); | 373 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"]); |
377 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex
t("foo.com#?#:-abp-properties(abc)")); | 374 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex
t("foo.com#?#:-abp-properties(abc)")); |
378 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"]); | 375 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"]); |
379 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"]); | 376 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"]); |
380 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"]); | 377 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"]); |
381 | 378 |
382 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. | 379 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. |
383 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"]); | 380 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"]); |
384 | 381 |
385 test.done(); | 382 test.done(); |
386 }; | 383 }; |
387 | 384 |
388 exports.testEmptyElemHideDomains = function(test) | 385 exports.testEmptyElemHideDomains = function(test) |
389 { | 386 { |
390 let emptyDomainFilters = [ | 387 let emptyDomainFilters = [ |
391 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", | 388 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |
392 ",foo.com##selector", "foo.com,~##selector", | 389 ",foo.com##selector", "foo.com,~##selector", |
393 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" | 390 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" |
(...skipping 19 matching lines...) Expand all Loading... |
413 "selector=#foo\\7B color: red\\7D ", | 410 "selector=#foo\\7B color: red\\7D ", |
414 "domains=" | 411 "domains=" |
415 ] | 412 ] |
416 ); | 413 ); |
417 compareFilter( | 414 compareFilter( |
418 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ | 415 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ |
419 "type=elemhideemulation", | 416 "type=elemhideemulation", |
420 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", | 417 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", |
421 "selectorDomains=foo.com", | 418 "selectorDomains=foo.com", |
422 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 419 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", |
423 "domains=FOO.COM" | 420 "domains=foo.com" |
424 ] | 421 ] |
425 ); | 422 ); |
426 test.done(); | 423 test.done(); |
427 }; | 424 }; |
428 | 425 |
429 exports.testFilterNormalization = function(test) | 426 exports.testFilterNormalization = function(test) |
430 { | 427 { |
431 // Line breaks etc | 428 // Line breaks etc |
432 test.equal(Filter.normalize("\n\t\nad\ns"), | 429 test.equal(Filter.normalize("\n\t\nad\ns"), |
433 "ads"); | 430 "ads"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 ); | 468 ); |
472 test.equal( | 469 test.equal( |
473 normalized, | 470 normalized, |
474 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" | 471 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" |
475 ); | 472 ); |
476 compareFilter( | 473 compareFilter( |
477 test, normalized, [ | 474 test, normalized, [ |
478 "type=filterlist", | 475 "type=filterlist", |
479 "text=" + normalized, | 476 "text=" + normalized, |
480 "csp=c s p", | 477 "csp=c s p", |
481 "domains=DOMAIN.COM|FOO.COM", | 478 "domains=domain.com|foo.com", |
482 "sitekeys=FOO", | 479 "sitekeys=FOO", |
483 "regexp=b\\$la", | 480 "regexp=b\\$la", |
484 "contentType=" + t.CSP | 481 "contentType=" + t.CSP |
485 ] | 482 ] |
486 ); | 483 ); |
487 | 484 |
488 // Some $csp edge cases | 485 // Some $csp edge cases |
489 test.equal(Filter.normalize("$csp= "), | 486 test.equal(Filter.normalize("$csp= "), |
490 "$csp="); | 487 "$csp="); |
491 test.equal(Filter.normalize("$csp= c s p"), | 488 test.equal(Filter.normalize("$csp= c s p"), |
492 "$csp=c s p"); | 489 "$csp=c s p"); |
493 test.equal(Filter.normalize("$$csp= c s p"), | 490 test.equal(Filter.normalize("$$csp= c s p"), |
494 "$$csp=c s p"); | 491 "$$csp=c s p"); |
495 test.equal(Filter.normalize("$$$csp= c s p"), | 492 test.equal(Filter.normalize("$$$csp= c s p"), |
496 "$$$csp=c s p"); | 493 "$$$csp=c s p"); |
497 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), | 494 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), |
498 "foo?csp=bar$csp=script-src 'self'"); | 495 "foo?csp=bar$csp=script-src 'self'"); |
499 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), | 496 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 541 |
545 test.equal( | 542 test.equal( |
546 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), | 543 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), |
547 "http://content.server/file/foo.txt/disable" | 544 "http://content.server/file/foo.txt/disable" |
548 ); | 545 ); |
549 test.equal( | 546 test.equal( |
550 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), | 547 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), |
551 "http://example.com/file/foo.txt/disable" | 548 "http://example.com/file/foo.txt/disable" |
552 ); | 549 ); |
553 | 550 |
| 551 // Example from https://github.com/uBlockOrigin/uBlock-issues/issues/46#issuec
omment-391190533 |
| 552 // The rewrite shouldn't happen. |
| 553 let rewriteEvil = "/(^https?:\\/\\/[^/])/$script,rewrite=$1.evil.com"; |
| 554 let filterEvil = Filter.fromText(rewriteEvil); |
| 555 |
| 556 test.equal( |
| 557 filterEvil.rewriteUrl("https://www.adblockplus.org/script.js"), |
| 558 "https://www.adblockplus.org/script.js" |
| 559 ); |
| 560 |
554 // Strip. | 561 // Strip. |
555 let rewriteStrip = "tag$rewrite="; | 562 let rewriteStrip = "tag$rewrite="; |
556 let filterStrip = Filter.fromText(rewriteStrip); | 563 let filterStrip = Filter.fromText(rewriteStrip); |
557 | 564 |
558 test.equal(filterStrip.rewrite, ""); | 565 test.equal(filterStrip.rewrite, ""); |
559 test.equal( | 566 test.equal( |
560 filterStrip.rewriteUrl("http://example.com/?tag"), | 567 filterStrip.rewriteUrl("http://example.com/?tag"), |
561 "http://example.com/?" | 568 "http://example.com/?" |
562 ); | 569 ); |
563 | 570 |
564 test.done(); | 571 test.done(); |
565 }; | 572 }; |
LEFT | RIGHT |