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: Added validate of element id, and fixed an infinite recursion in parsing. Created May 15, 2017, 6:10 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
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\]/;
Wladimir Palant 2017/05/16 13:50:39 We never released this syntax, no point for having
+const abpPropertySelectorRegExp = /\[-abp-properties=(["'])([^"']+)\1\]/;
Wladimir Palant 2017/05/16 13:50:40 I definitely think that there should be something
+
/**
* 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))
+ {
Wladimir Palant 2017/05/16 13:50:40 This *definitely* needs to go after the isExceptio
+ 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");
Wladimir Palant 2017/05/16 13:50:39 No need to duplicate code, we have that check done
+
+ 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)
Wladimir Palant 2017/05/16 13:50:40 How does that support :-abp-properties() and :-abp
{
// 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);
}

Powered by Google App Engine
This is Rietveld