Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/filterClasses.js

Issue 29801609: Issue 6733 - Allow empty values in filter options (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 7, 2018, 11:51 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/filterClasses.js ('K') | « lib/filterClasses.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterClasses.js
===================================================================
--- a/test/filterClasses.js
+++ b/test/filterClasses.js
@@ -292,16 +292,19 @@
exports.testFilterOptions = function(test)
{
compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,domain=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", "domains=FOO.COM", "sitekeys=FOO", "csp=first csp"]);
compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,domain=~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"]);
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", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]);
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=@@bla$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.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]);
compareFilter(test, "||content.server.com/files/*.php$rewrite=$1", ["type=filterlist", "text=||content.server.com/files/*.php$rewrite=$1", "regexp=^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?content\\.server\\.com\\/files\\/.*\\.php", "matchCase=false", "rewrite=$1", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.SUBDOCUMENT | t.OBJECT | t.OBJECT_SUBREQUEST))]);
+ // Blank values for domain, sitekey, and csp should be ignored.
+ compareFilter(test, "bla$match-case,csp=,script,other,third-party,domain=,sitekey=", ["type=filterlist", "text=bla$match-case,csp=,script,other,third-party,domain=,sitekey=", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true"]);
+
// background and image should be the same for backwards compatibility
compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp=bla", "contentType=" + (t.IMAGE)]);
compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background", "regexp=bla", "contentType=" + (t.IMAGE)]);
compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~background", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
@@ -478,16 +481,18 @@
"domains=DOMAIN.COM|FOO.COM",
"sitekeys=FOO",
"regexp=b\\$la",
"contentType=" + t.CSP
]
);
// Some $csp edge cases
+ test.equal(Filter.normalize("$csp= "),
+ "$csp=");
test.equal(Filter.normalize("$csp= c s p"),
"$csp=c s p");
test.equal(Filter.normalize("$$csp= c s p"),
"$$csp=c s p");
test.equal(Filter.normalize("$$$csp= c s p"),
"$$$csp=c s p");
test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"),
"foo?csp=bar$csp=script-src 'self'");
@@ -541,10 +546,20 @@
filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"),
"http://content.server/file/foo.txt/disable"
);
test.equal(
filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"),
"http://example.com/file/foo.txt/disable"
);
+ // Strip.
+ let rewriteStrip = "tag$rewrite=";
+ let filterStrip = Filter.fromText(rewriteStrip);
+
+ test.equal(filterStrip.rewrite, "");
+ test.equal(
+ filterStrip.rewriteUrl("http://example.com/?tag"),
+ "http://example.com/?"
+ );
+
test.done();
};
« lib/filterClasses.js ('K') | « lib/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld