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

Unified Diff: lib/filterClasses.js

Issue 29470687: Issue 5344 - Element hiding emulation exceptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 21, 2017, 6:50 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 | « lib/elemHide.js ('k') | test/filterClasses.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
@@ -82,17 +82,17 @@
* @type {Object}
*/
Filter.knownFilters = Object.create(null);
/**
* Regular expression that element hiding filters should match
* @type {RegExp}
*/
-Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/;
+Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?^])?#(.+)$/;
/**
* Regular expression that RegExp filters specified as RegExps should match
* @type {RegExp}
*/
Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)?$/;
/**
* Regular expression that options on a RegExp filter should match
* @type {RegExp}
@@ -943,43 +943,63 @@
*
* @param {string} text same as in Filter()
* @param {string?} domain
* domain part of the text representation
* @param {string?} type
* rule type, either empty or @ (exception) or ? (emulation rule)
* @param {string} selector raw CSS selector
* @return {ElemHideFilter|ElemHideException|
- * ElemHideEmulationFilter|InvalidFilter}
+ * ElemHideEmulationFilter|ElemHideEmulationException|InvalidFilter}
*/
ElemHideBase.fromText = function(text, domain, type, selector)
{
// 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");
if (type == "@")
return new ElemHideException(text, domain, selector);
- if (type == "?")
+ if ((type == "?") || (type == "^"))
{
// 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");
+ if (type == "^")
+ return new ElemHideEmulationException(text, domain, selector);
+
return new ElemHideEmulationFilter(text, domain, selector);
}
return new ElemHideFilter(text, domain, selector);
};
/**
+ * Base class for element hiding exceptions
+ * @param {string} text see Filter()
+ * @param {string} domains see ElemHideBase()
+ * @param {string} selector see ElemHideBase()
+ * @constructor
+ * @augments ElemHideBase
+ */
+function ElemHideExceptionBase(text, domains, selector)
+{
+ ElemHideBase.call(this, text, domains, selector);
+}
+exports.ElemHideExceptionBase = ElemHideExceptionBase;
+
+ElemHideExceptionBase.prototype = extend(ElemHideBase, {
+});
+
+/**
* Class for element hiding filters
* @param {string} text see Filter()
* @param {string} domains see ElemHideBase()
* @param {string} selector see ElemHideBase()
* @constructor
* @augments ElemHideBase
*/
function ElemHideFilter(text, domains, selector)
@@ -993,25 +1013,25 @@
});
/**
* Class for element hiding exceptions
* @param {string} text see Filter()
* @param {string} domains see ElemHideBase()
* @param {string} selector see ElemHideBase()
* @constructor
- * @augments ElemHideBase
+ * @augments ElemHideExceptionBase
*/
function ElemHideException(text, domains, selector)
{
- ElemHideBase.call(this, text, domains, selector);
+ ElemHideExceptionBase.call(this, text, domains, selector);
}
exports.ElemHideException = ElemHideException;
-ElemHideException.prototype = extend(ElemHideBase, {
+ElemHideException.prototype = extend(ElemHideExceptionBase, {
type: "elemhideexception"
});
/**
* Class for element hiding emulation filters
* @param {string} text see Filter()
* @param {string} domains see ElemHideBase()
* @param {string} selector see ElemHideBase()
@@ -1022,8 +1042,26 @@
{
ElemHideBase.call(this, text, domains, selector);
}
exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
type: "elemhideemulation"
});
+
+/**
+ * Class for element hiding emulation exceptions
+ * @param {string} text see Filter()
+ * @param {string} domains see ElemHideBase()
+ * @param {string} selector see ElemHideBase()
+ * @constructor
+ * @augments ElemHideExceptionBase
+ */
+function ElemHideEmulationException(text, domains, selector)
+{
+ ElemHideExceptionBase.call(this, text, domains, selector);
+}
+exports.ElemHideEmulationException = ElemHideEmulationException;
+
+ElemHideEmulationException.prototype = extend(ElemHideExceptionBase, {
+ type: "elemhideemulationexception"
+});
« no previous file with comments | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld