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

Unified Diff: lib/contentBlockerLists.js

Issue 29336787: Issue 3670 - Make rules case sensitive where possible (Closed)
Patch Set: Created Feb. 21, 2016, 1:48 p.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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/contentBlockerLists.js
diff --git a/lib/contentBlockerLists.js b/lib/contentBlockerLists.js
index 95b94fc16eda818c6e2f692c0cd5b8f789b0cc32..a7c2e32847501c2d656c3c2ff4482e9c9585a7e2 100644
--- a/lib/contentBlockerLists.js
+++ b/lib/contentBlockerLists.js
@@ -172,12 +172,32 @@ function addDomainPrefix(domains)
return result;
}
+function caseSensitive(filter)
Sebastian Noack 2016/02/21 21:42:30 It probably makes sense to integrate the logic her
kzar 2016/02/24 15:43:29 Done.
+{
+ if (filter.matchCase)
+ return true;
+
+ if (!(filter.text.startsWith("||") || filter.text.startsWith("://")))
Sebastian Noack 2016/02/21 21:42:30 Filters usually don't start with "://". But filter
kzar 2016/02/24 15:43:29 Done.
+ return false;
+
+ let offset = filter.text.startsWith("||") ? 2 : 3;
+ let boundary = filter.text.substr(offset).search(/\/\?\*\^/);
Sebastian Noack 2016/02/21 21:42:30 This regular expression would only match a seqeunc
kzar 2016/02/24 15:43:29 (Yep, forgot the brackets.)
+
+ if (boundary == -1)
+ return true;
+
+ return filter.text.substr(offset + boundary + 1).search(/[a-zA-Z]/) == -1;
+}
+
function convertFilter(filter, action, withResourceTypes)
{
let trigger = {"url-filter": getRegExpSource(filter)};
let included = [];
let excluded = [];
+ if (caseSensitive(filter))
+ trigger["url-filter-is-case-sensitive"] = true;
+
parseDomains(filter.domains, included, excluded);
if (withResourceTypes)
@@ -362,7 +382,8 @@ exports.convertFilters = function(filters)
selector = convertIDSelectorsToAttributeSelectors(selector);
addRule({
- trigger: {"url-filter": matchDomain},
+ trigger: {"url-filter": matchDomain,
Sebastian Noack 2016/02/21 21:42:30 Same for element hiding filters; we have to make s
kzar 2016/02/24 15:43:29 Done.
+ "url-filter-is-case-sensitive": true},
action: {type: "css-display-none",
selector: selector}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld