 Issue 30045566:
  Fixed #4 - Disable rewrite option for all but internal redirect  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluscore/
    
  
    Issue 30045566:
  Fixed #4 - Disable rewrite option for all but internal redirect  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluscore/| Left: | ||
| Right: | 
| 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=ab p-resource:noopjs", "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=abp- resource:noopjs", "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=abp-resource:noopjs", "thirdParty=false", "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"]); | |
| 
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.
 | |
| 335 | 332 | 
| 336 // background and image should be the same for backwards compatibility | 333 // background and image should be the same for backwards compatibility | 
| 337 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "conten tType=" + (t.IMAGE)]); | 334 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)]); | 335 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)]); | 336 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)]); | 337 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 
| 341 | 338 | 
| 342 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); | 339 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))]); | 340 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))]); | 341 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); | 
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 "||content.server.com/files/*.php$rewrite=$1"); | 557 "||content.server.com/files/*.php$rewrite=$1"); | 
| 561 test.done(); | 558 test.done(); | 
| 562 }; | 559 }; | 
| 563 | 560 | 
| 564 exports.testFilterRewriteOption = function(test) | 561 exports.testFilterRewriteOption = function(test) | 
| 565 { | 562 { | 
| 566 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; | 563 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1"; | 
| 567 | 564 | 
| 568 let filter = Filter.fromText(text); | 565 let filter = Filter.fromText(text); | 
| 569 | 566 | 
| 570 test.equal(filter.rewrite, "$1"); | 567 test.ok(filter instanceof InvalidFilter); | 
| 571 // no rewrite occured: didn't match. | |
| 572 test.equal(filter.rewriteUrl("foo"), "foo"); | |
| 573 // rewrite occured: matched. | |
| 574 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"), | |
| 575 "http://content.server/file/foo.txt"); | |
| 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 | 568 | 
| 621 test.done(); | 569 test.done(); | 
| 622 }; | 570 }; | 
| 623 | 571 | 
| 624 exports.testDomainMapDeduplication = function(test) | 572 exports.testDomainMapDeduplication = function(test) | 
| 625 { | 573 { | 
| 626 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); | 574 let filter1 = Filter.fromText("foo$domain=blocking.example.com"); | 
| 627 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); | 575 let filter2 = Filter.fromText("bar$domain=blocking.example.com"); | 
| 628 let filter3 = Filter.fromText("elemhide.example.com##.foo"); | 576 let filter3 = Filter.fromText("elemhide.example.com##.foo"); | 
| 629 let filter4 = Filter.fromText("elemhide.example.com##.bar"); | 577 let filter4 = Filter.fromText("elemhide.example.com##.bar"); | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 643 | 591 | 
| 644 test.notEqual(filter2.domains, filter5.domains); | 592 test.notEqual(filter2.domains, filter5.domains); | 
| 645 | 593 | 
| 646 // Check twice for element hiding filters to make sure the internal cached | 594 // Check twice for element hiding filters to make sure the internal cached | 
| 647 // values are also not equal. | 595 // values are also not equal. | 
| 648 test.notEqual(filter4.domains, filter6.domains); | 596 test.notEqual(filter4.domains, filter6.domains); | 
| 649 test.notEqual(filter4.domains, filter6.domains); | 597 test.notEqual(filter4.domains, filter6.domains); | 
| 650 | 598 | 
| 651 test.done(); | 599 test.done(); | 
| 652 }; | 600 }; | 
| OLD | NEW |