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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 test.done(); | 303 test.done(); |
304 }; | 304 }; |
305 | 305 |
306 exports.testSpecialCharacters = function(test) | 306 exports.testSpecialCharacters = function(test) |
307 { | 307 { |
308 compareFilter(test, "/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/",
"regexp=ddd|f?a[s]d"]); | 308 compareFilter(test, "/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/",
"regexp=ddd|f?a[s]d"]); |
309 compareFilter(test, "*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", "
regexp=asdf.*d.*dd"]); | 309 compareFilter(test, "*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", "
regexp=asdf.*d.*dd"]); |
310 compareFilter(test, "|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd
*|", "regexp=^.*asd\\|f.*d.*dd.*$"]); | 310 compareFilter(test, "|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd
*|", "regexp=^.*asd\\|f.*d.*dd.*$"]); |
311 compareFilter(test, "dd[]{}$%<>&()*d", ["type=filterlist", "text=dd[]{}$%<>&()
*d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d"]); | 311 compareFilter(test, "dd[]{}$%<>&()*d", ["type=filterlist", "text=dd[]{}$%<>&()
*d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d"]); |
312 | 312 |
313 // Leading and trailing wildcards should be left in for rewrite filters (#6868
). | |
314 compareFilter(test, "*asdf*d**dd*$rewrite=", ["type=filterlist", "text=*asdf*d
**dd*$rewrite=", "regexp=.*asdf.*d.*dd.*", "rewrite=", "contentType=" + (default
Types & ~(t.SCRIPT | t.SUBDOCUMENT | t.OBJECT | t.OBJECT_SUBREQUEST))]); | |
315 | |
316 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); | 313 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d
/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); |
317 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); | 314 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*"
, "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); |
318 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); | 315 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d*
*dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); |
319 compareFilter(test, "@@dd[]{}$%<>&()*d", ["type=whitelist", "text=@@dd[]{}$%<>
&()*d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d", "contentType=" + defaul
tTypes]); | 316 compareFilter(test, "@@dd[]{}$%<>&()*d", ["type=whitelist", "text=@@dd[]{}$%<>
&()*d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d", "contentType=" + defaul
tTypes]); |
320 | 317 |
321 test.done(); | 318 test.done(); |
322 }; | 319 }; |
323 | 320 |
324 exports.testFilterOptions = function(test) | 321 exports.testFilterOptions = function(test) |
325 { | 322 { |
326 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", "matchCase=true", "conten
tType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=foo.com", "s
itekeys=FOO", "csp=first csp"]); | 323 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", "matchCase=true", "conten
tType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=foo.com", "s
itekeys=FOO", "csp=first csp"]); |
327 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", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.O
THER)), "thirdParty=false", "domains=~bar.com"]); | 324 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", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.O
THER)), "thirdParty=false", "domains=~bar.com"]); |
328 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", "matchCase=true", "contentType=" +
(t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=bar.com|foo.com|~bar.
foo.com|~foo.bar.com", "sitekeys=BAR|FOO"]); | 325 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", "matchCase=true", "contentType=" +
(t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=bar.com|foo.com|~bar.
foo.com|~foo.bar.com", "sitekeys=BAR|FOO"]); |
329 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", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER
), "thirdParty=true", "domains=bar.com|foo.com|~bar.foo.com|~foo.bar.com", "site
keys=BAR|FOO"]); | 326 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", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER
), "thirdParty=true", "domains=bar.com|foo.com|~bar.foo.com|~foo.bar.com", "site
keys=BAR|FOO"]); |
330 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))]); | |
331 | 327 |
332 compareFilter(test, "||example.com/ad.js$rewrite=abp-resource:noopjs,domain=fo
o.com|bar.com", ["type=filterlist", "text=||example.com/ad.js$rewrite=abp-resour
ce:noopjs,domain=foo.com|bar.com", "regexp=null", "matchCase=false", "rewrite=ab
p-resource:noopjs", "contentType=" + (defaultTypes), "domains=bar.com|foo.com"])
; | 328 compareFilter(test, "||example.com/ad.js$rewrite=abp-resource:noopjs,domain=fo
o.com|bar.com", ["type=filterlist", "text=||example.com/ad.js$rewrite=abp-resour
ce:noopjs,domain=foo.com|bar.com", "regexp=null", "matchCase=false", "rewrite=no
opjs", "contentType=" + (defaultTypes), "domains=bar.com|foo.com"]); |
333 compareFilter(test, "*example.com/ad.js$rewrite=abp-resource:noopjs,domain=foo
.com|bar.com", ["type=filterlist", "text=*example.com/ad.js$rewrite=abp-resource
:noopjs,domain=foo.com|bar.com", "regexp=null", "matchCase=false", "rewrite=abp-
resource:noopjs", "contentType=" + (defaultTypes), "domains=bar.com|foo.com"]); | 329 compareFilter(test, "*example.com/ad.js$rewrite=abp-resource:noopjs,domain=foo
.com|bar.com", ["type=filterlist", "text=*example.com/ad.js$rewrite=abp-resource
:noopjs,domain=foo.com|bar.com", "regexp=null", "matchCase=false", "rewrite=noop
js", "contentType=" + (defaultTypes), "domains=bar.com|foo.com"]); |
334 compareFilter(test, "||example.com/ad.js$rewrite=abp-resource:noopjs,~third-pa
rty", ["type=filterlist", "text=||example.com/ad.js$rewrite=abp-resource:noopjs,
~third-party", "regexp=null", "matchCase=false", "rewrite=abp-resource:noopjs",
"thirdParty=false", "contentType=" + (defaultTypes)]); | 330 compareFilter(test, "||example.com/ad.js$rewrite=abp-resource:noopjs,~third-pa
rty", ["type=filterlist", "text=||example.com/ad.js$rewrite=abp-resource:noopjs,
~third-party", "regexp=null", "matchCase=false", "rewrite=noopjs", "thirdParty=f
alse", "contentType=" + (defaultTypes)]); |
| 331 compareFilter(test, "||content.server.com/files/*.php$rewrite=$1", ["type=inva
lid", "reason=filter_invalid_rewrite", "text=||content.server.com/files/*.php$re
write=$1"]); |
| 332 compareFilter(test, "||content.server.com/files/*.php$rewrite=", ["type=invali
d", "reason=filter_invalid_rewrite", "text=||content.server.com/files/*.php$rewr
ite="]); |
335 | 333 |
336 // background and image should be the same for backwards compatibility | 334 // background and image should be the same for backwards compatibility |
337 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "conten
tType=" + (t.IMAGE)]); | 335 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "conten
tType=" + (t.IMAGE)]); |
338 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "contentType=" + (t.IMAGE)]); | 336 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "contentType=" + (t.IMAGE)]); |
339 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "cont
entType=" + (defaultTypes & ~t.IMAGE)]); | 337 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "cont
entType=" + (defaultTypes & ~t.IMAGE)]); |
340 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 338 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
341 | 339 |
342 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); | 340 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); |
343 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); | 341 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); |
344 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 342 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), | 555 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), |
558 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); | 556 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); |
559 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"), | 557 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"), |
560 "||content.server.com/files/*.php$rewrite=$1"); | 558 "||content.server.com/files/*.php$rewrite=$1"); |
561 test.done(); | 559 test.done(); |
562 }; | 560 }; |
563 | 561 |
564 exports.testFilterRewriteOption = function(test) | 562 exports.testFilterRewriteOption = function(test) |
565 { | 563 { |
566 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; | 564 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; |
| 565 let filter = Filter.fromText(text); |
| 566 test.ok(filter instanceof InvalidFilter); |
567 | 567 |
568 let filter = Filter.fromText(text); | 568 text = "||/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=blank-text,doma
ins=content.server"; |
| 569 filter = Filter.fromText(text); |
| 570 test.ok(filter instanceof InvalidFilter); |
569 | 571 |
570 test.equal(filter.rewrite, "$1"); | 572 text = "||/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=abp-resource:bl
ank-text,domain=content.server"; |
571 // no rewrite occured: didn't match. | 573 filter = Filter.fromText(text); |
572 test.equal(filter.rewriteUrl("foo"), "foo"); | 574 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt"), |
573 // rewrite occured: matched. | 575 "data:text/plain,"); |
574 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"), | 576 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"), |
575 "http://content.server/file/foo.txt"); | 577 "data:text/plain,"); |
576 | |
577 // checking for same origin. | |
578 let rewriteDiffOrigin = | |
579 "/content\\.server(\\/file\\/.*\\.txt)\\?.*$/$rewrite=foo.com$1"; | |
580 let filterDiffOrigin = Filter.fromText(rewriteDiffOrigin); | |
581 | |
582 // no rewrite occured because of a different origin. | |
583 test.equal( | |
584 filterDiffOrigin.rewriteUrl("http://content.server/file/foo.txt?bar"), | |
585 "http://content.server/file/foo.txt?bar" | |
586 ); | |
587 | |
588 // relative path. | |
589 let rewriteRelative = "/(\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1/disable"; | |
590 let filterRelative = Filter.fromText(rewriteRelative); | |
591 | |
592 test.equal( | |
593 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), | |
594 "http://content.server/file/foo.txt/disable" | |
595 ); | |
596 test.equal( | |
597 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), | |
598 "http://example.com/file/foo.txt/disable" | |
599 ); | |
600 | |
601 // Example from https://github.com/uBlockOrigin/uBlock-issues/issues/46#issuec
omment-391190533 | |
602 // The rewrite shouldn't happen. | |
603 let rewriteEvil = "/(^https?:\\/\\/[^/])/$script,rewrite=$1.evil.com"; | |
604 let filterEvil = Filter.fromText(rewriteEvil); | |
605 | |
606 test.equal( | |
607 filterEvil.rewriteUrl("https://www.adblockplus.org/script.js"), | |
608 "https://www.adblockplus.org/script.js" | |
609 ); | |
610 | |
611 // Strip. | |
612 let rewriteStrip = "tag$rewrite="; | |
613 let filterStrip = Filter.fromText(rewriteStrip); | |
614 | |
615 test.equal(filterStrip.rewrite, ""); | |
616 test.equal( | |
617 filterStrip.rewriteUrl("http://example.com/?tag"), | |
618 "http://example.com/?" | |
619 ); | |
620 | 578 |
621 test.done(); | 579 test.done(); |
622 }; | 580 }; |
623 | 581 |
624 exports.testDomainMapDeduplication = function(test) | 582 exports.testDomainMapDeduplication = function(test) |
625 { | 583 { |
626 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); | 584 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); |
627 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); | 585 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); |
628 let filter3 = Filter.fromText("elemhide.example.com##.foo"); | 586 let filter3 = Filter.fromText("elemhide.example.com##.foo"); |
629 let filter4 = Filter.fromText("elemhide.example.com##.bar"); | 587 let filter4 = Filter.fromText("elemhide.example.com##.bar"); |
(...skipping 13 matching lines...) Expand all Loading... |
643 | 601 |
644 test.notEqual(filter2.domains, filter5.domains); | 602 test.notEqual(filter2.domains, filter5.domains); |
645 | 603 |
646 // Check twice for element hiding filters to make sure the internal cached | 604 // Check twice for element hiding filters to make sure the internal cached |
647 // values are also not equal. | 605 // values are also not equal. |
648 test.notEqual(filter4.domains, filter6.domains); | 606 test.notEqual(filter4.domains, filter6.domains); |
649 test.notEqual(filter4.domains, filter6.domains); | 607 test.notEqual(filter4.domains, filter6.domains); |
650 | 608 |
651 test.done(); | 609 test.done(); |
652 }; | 610 }; |
OLD | NEW |