| 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"); |
| const {Utils} = require("utils"); |
| /** |
| * 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. |
| @@ -106,16 +106,32 @@ |
| } |
| catch (e) |
| { |
| return false; |
| } |
| return true; |
| } |
| +function isValidFilterSelector(filter) |
| +{ |
| + // Only ElemHideBase has selectors |
|
kzar
2018/04/05 15:00:27
Perhaps split these up a bit? Something like this
hub
2018/04/05 17:04:41
Done.
|
| + // We don't check the syntax of ElemHideEmulationFilter yet |
| + if (!(filter instanceof ElemHideBase) |
| + || (filter instanceof ElemHideEmulationFilter)) |
|
kzar
2018/04/05 15:00:27
Nit: Parenthesis around the second clause seem red
hub
2018/04/05 17:04:41
Done.
|
| + return true; |
|
kzar
2018/04/05 15:00:27
Nit: I think a newline between these cases would l
hub
2018/04/05 17:04:41
Done.
|
| + // If it ElemHideException, don't check if it is |
| + // for an EmulationFilter |
| + if ((filter instanceof ElemHideException) && |
| + (filter.selector.indexOf(":-abp-") != -1)) |
|
kzar
2018/04/05 15:00:27
Is this check good enough now that we support :has
hub
2018/04/05 17:04:41
This idea is that like above if we have one of the
kzar
2018/04/06 10:05:44
Acknowledged.
|
| + 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} |
| */ |
| @@ -138,19 +154,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}; |
| }; |