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

Unified Diff: lib/filterValidation.js

Issue 29636648: Issue 6193 - Allow element hiding emulation exceptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Updated following feedback Created April 5, 2018, 5:04 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/filterValidation.js
===================================================================
--- a/lib/filterValidation.js
+++ b/lib/filterValidation.js
@@ -14,18 +14,18 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/** @module filterValidation */
"use strict";
-const {Filter, InvalidFilter, ElemHideBase, ElemHideEmulationFilter} =
- require("filterClasses");
+const {Filter, InvalidFilter, ElemHideBase, ElemHideException,
+ ElemHideEmulationFilter} = require("filterClasses");
/**
* An error returned by
* {@link module:filterValidation.parseFilter parseFilter()} or
* {@link module:filterValidation.parseFilters parseFilters()}
* indicating that a given filter cannot be parsed,
* contains an invalid CSS selector or is a filter list header.
*
@@ -105,16 +105,37 @@
}
catch (e)
{
return false;
}
return true;
}
+function isValidFilterSelector(filter)
+{
+ // Only ElemHideBase has selectors.
+ if (!(filter instanceof ElemHideBase))
+ return true;
+
+ // We don't check the syntax of ElemHideEmulationFilter yet.
+ if (filter instanceof ElemHideEmulationFilter)
+ return true;
+
+ // If it is an ElemHideException, and it has an extended CSS
+ // selector we don't validate and assume it is valid.
+ if (filter instanceof ElemHideException &&
+ filter.selector.includes(":-abp-"))
+ {
+ return true;
+ }
+
+ return isValidCSSSelector(filter.selector);
+}
+
/**
* @typedef ParsedFilter
* @property {?Filter} [filter]
* The parsed filter if it is valid. Or null if the given string is empty.
* @property {FilterParsingError} [error]
* See {@link module:filterValidation~FilterParsingError FilterParsingError}
*/
@@ -137,19 +158,17 @@
filter = Filter.fromText(text);
if (filter instanceof InvalidFilter)
{
return {error: new FilterParsingError("invalid-filter",
{reason: filter.reason})};
}
- if (filter instanceof ElemHideBase &&
- !(filter instanceof ElemHideEmulationFilter) &&
- !isValidCSSSelector(filter.selector))
+ if (!isValidFilterSelector(filter))
{
return {error: new FilterParsingError("invalid-css-selector",
{selector: filter.selector})};
}
}
return {filter};
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld