Left: | ||
Right: |
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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 test.done(); | 318 test.done(); |
319 }; | 319 }; |
320 | 320 |
321 exports.testFilterOptions = function(test) | 321 exports.testFilterOptions = function(test) |
322 { | 322 { |
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"]); | 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"]); |
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"]); | 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"]); |
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"]); | 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"]); |
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"]); | 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"]); |
327 | 327 |
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=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"]); |
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=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"]); |
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=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"]); | 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"]); |
Manish Jethani
2019/04/15 21:48:49
Let's add a test for just `$rewrite=` (no value) a
hub
2019/04/16 04:56:24
Done.
| |
332 compareFilter(test, "||content.server.com/files/*.php$rewrite=", ["type=invali d", "reason=filter_invalid_rewrite", "text=||content.server.com/files/*.php$rewr ite="]); | |
332 | 333 |
333 // background and image should be the same for backwards compatibility | 334 // background and image should be the same for backwards compatibility |
334 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)]); |
335 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)]); |
336 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)]); |
337 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)]); |
338 | 339 |
339 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))]); |
340 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))]); |
341 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... | |
554 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"), |
555 "/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"); |
556 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"), | 557 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"), |
557 "||content.server.com/files/*.php$rewrite=$1"); | 558 "||content.server.com/files/*.php$rewrite=$1"); |
558 test.done(); | 559 test.done(); |
559 }; | 560 }; |
560 | 561 |
561 exports.testFilterRewriteOption = function(test) | 562 exports.testFilterRewriteOption = function(test) |
562 { | 563 { |
563 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; | 564 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; |
564 | |
565 let filter = Filter.fromText(text); | 565 let filter = Filter.fromText(text); |
566 | |
567 test.ok(filter instanceof InvalidFilter); | 566 test.ok(filter instanceof InvalidFilter); |
567 test.equal(filter.type, "invalid"); | |
568 test.equal(filter.reason, "filter_invalid_rewrite"); | |
569 | |
570 text = "||/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=blank-text,doma ins=content.server"; | |
571 filter = Filter.fromText(text); | |
572 test.ok(filter instanceof InvalidFilter); | |
573 test.equal(filter.type, "invalid"); | |
574 test.equal(filter.reason, "filter_invalid_rewrite"); | |
575 | |
576 text = "||/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=abp-resource:bl ank-text,domain=content.server"; | |
577 filter = Filter.fromText(text); | |
578 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt"), | |
579 "data:text/plain,"); | |
580 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"), | |
581 "data:text/plain,"); | |
568 | 582 |
569 test.done(); | 583 test.done(); |
570 }; | 584 }; |
571 | 585 |
572 exports.testDomainMapDeduplication = function(test) | 586 exports.testDomainMapDeduplication = function(test) |
573 { | 587 { |
574 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); | 588 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); |
575 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); | 589 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); |
576 let filter3 = Filter.fromText("elemhide.example.com##.foo"); | 590 let filter3 = Filter.fromText("elemhide.example.com##.foo"); |
577 let filter4 = Filter.fromText("elemhide.example.com##.bar"); | 591 let filter4 = Filter.fromText("elemhide.example.com##.bar"); |
(...skipping 13 matching lines...) Expand all Loading... | |
591 | 605 |
592 test.notEqual(filter2.domains, filter5.domains); | 606 test.notEqual(filter2.domains, filter5.domains); |
593 | 607 |
594 // Check twice for element hiding filters to make sure the internal cached | 608 // Check twice for element hiding filters to make sure the internal cached |
595 // values are also not equal. | 609 // values are also not equal. |
596 test.notEqual(filter4.domains, filter6.domains); | 610 test.notEqual(filter4.domains, filter6.domains); |
597 test.notEqual(filter4.domains, filter6.domains); | 611 test.notEqual(filter4.domains, filter6.domains); |
598 | 612 |
599 test.done(); | 613 test.done(); |
600 }; | 614 }; |
LEFT | RIGHT |