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

Unified Diff: lib/filterClasses.js

Issue 29383960: Issue 3143 - Filter elements with :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Now we properly upgrade to the new syntax for [-abp-properties=] Created May 4, 2017, 6:45 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 | « chrome/content/elemHideEmulation.js ('k') | test/browser/elemHideEmulation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -921,16 +921,19 @@
selectorDomain: null,
/**
* CSS selector for the HTML elements that should be hidden
* @type {string}
*/
selector: null
});
+const abpSelectorRegExp = /\[-abp-selector=(["'])(.+)\1\]/;
+const abpPropertySelectorRegExp = /\[-abp-properties=(["'])([^"']+)\1\]/;
+
/**
* Creates an element hiding filter from a pre-parsed text representation
*
* @param {string} text same as in Filter()
* @param {string} domain
* domain part of the text representation (can be empty)
* @param {boolean} isException exception rule indicator
* @param {string} tagName tag name part (can be empty)
@@ -980,20 +983,48 @@
}
// We don't allow ElemHide filters which have any empty domains.
// Note: The ElemHide.prototype.domainSeparator is duplicated here, if that
// changes this must be changed too.
if (domain && /(^|,)~?(,|$)/.test(domain))
return new InvalidFilter(text, "filter_invalid_domain");
+ let isHideEmulation = false;
+ if ((selector.indexOf("[-abp-properties=") != -1) ||
+ (selector.indexOf("[-abp-selector=") != -1))
+ {
+ isHideEmulation = true;
+
+ // Element hiding emulation filters are inefficient so we need to make sure
+ // that they're only applied if they specify active domains
+ if (!/,[^~][^,.]*\.[^,]/.test("," + domain))
+ return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
+
+ let match = abpSelectorRegExp.exec(selector);
+ if (match)
+ {
+ let prefix = selector.substr(0, match.index);
+ let suffix = selector.substr(match.index + match[0].length);
+ selector = prefix + match[2] + suffix;
+ }
+ match = abpPropertySelectorRegExp.exec(selector);
+ if (match)
+ {
+ let prefix = selector.substr(0, match.index);
+ let suffix = selector.substr(match.index + match[0].length);
+ selector = prefix + ":-abp-properties(" +
+ match[1] + match[2] + match[1] + ")" + suffix;
+ }
+ }
+
if (isException)
return new ElemHideException(text, domain, selector);
- if (selector.indexOf("[-abp-properties=") != -1)
+ if (isHideEmulation)
{
// Element hiding emulation filters are inefficient so we need to make sure
// that they're only applied if they specify active domains
if (!/,[^~][^,.]*\.[^,]/.test("," + domain))
return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
return new ElemHideEmulationFilter(text, domain, selector);
}
« no previous file with comments | « chrome/content/elemHideEmulation.js ('k') | test/browser/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld