| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 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 |
| 300 // background and image should be the same for backwards compatibility | 303 // background and image should be the same for backwards compatibility |
| 301 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); | 304 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp
=bla", "contentType=" + (t.IMAGE)]); |
| 302 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); | 305 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background
", "regexp=bla", "contentType=" + (t.IMAGE)]); |
| 303 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 306 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege
xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
| 304 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); | 307 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou
nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); |
| 305 | 308 |
| 306 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); | 309 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc
ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE
R))]); |
| 307 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); | 310 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@
http://bla$~script,~other", "regexp=http\\:\\/\\/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))]); | 311 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@
|ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default
Types & ~(t.SCRIPT | t.OTHER))]); |
| 309 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text=
@@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); | 312 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text=
@@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~
(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 "text=" + normalized, | 479 "text=" + normalized, |
| 477 "csp=c s p", | 480 "csp=c s p", |
| 478 "domains=DOMAIN.COM|FOO.COM", | 481 "domains=DOMAIN.COM|FOO.COM", |
| 479 "sitekeys=FOO", | 482 "sitekeys=FOO", |
| 480 "regexp=b\\$la", | 483 "regexp=b\\$la", |
| 481 "contentType=" + t.CSP | 484 "contentType=" + t.CSP |
| 482 ] | 485 ] |
| 483 ); | 486 ); |
| 484 | 487 |
| 485 // Some $csp edge cases | 488 // Some $csp edge cases |
| 489 test.equal(Filter.normalize("$csp= "), |
| 490 "$csp="); |
| 486 test.equal(Filter.normalize("$csp= c s p"), | 491 test.equal(Filter.normalize("$csp= c s p"), |
| 487 "$csp=c s p"); | 492 "$csp=c s p"); |
| 488 test.equal(Filter.normalize("$$csp= c s p"), | 493 test.equal(Filter.normalize("$$csp= c s p"), |
| 489 "$$csp=c s p"); | 494 "$$csp=c s p"); |
| 490 test.equal(Filter.normalize("$$$csp= c s p"), | 495 test.equal(Filter.normalize("$$$csp= c s p"), |
| 491 "$$$csp=c s p"); | 496 "$$$csp=c s p"); |
| 492 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), | 497 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"), |
| 493 "foo?csp=bar$csp=script-src 'self'"); | 498 "foo?csp=bar$csp=script-src 'self'"); |
| 494 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), | 499 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"), |
| 495 "foo$bar=csp=baz,csp=script-src 'self'"); | 500 "foo$bar=csp=baz,csp=script-src 'self'"); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 544 |
| 540 test.equal( | 545 test.equal( |
| 541 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), | 546 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), |
| 542 "http://content.server/file/foo.txt/disable" | 547 "http://content.server/file/foo.txt/disable" |
| 543 ); | 548 ); |
| 544 test.equal( | 549 test.equal( |
| 545 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), | 550 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), |
| 546 "http://example.com/file/foo.txt/disable" | 551 "http://example.com/file/foo.txt/disable" |
| 547 ); | 552 ); |
| 548 | 553 |
| 554 // Strip. |
| 555 let rewriteStrip = "tag$rewrite="; |
| 556 let filterStrip = Filter.fromText(rewriteStrip); |
| 557 |
| 558 test.equal(filterStrip.rewrite, ""); |
| 559 test.equal( |
| 560 filterStrip.rewriteUrl("http://example.com/?tag"), |
| 561 "http://example.com/?" |
| 562 ); |
| 563 |
| 549 test.done(); | 564 test.done(); |
| 550 }; | 565 }; |
| OLD | NEW |