| 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}; |
| }; |