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

Delta Between Two Patch Sets: lib/content/elemHideEmulation.js

Issue 29613805: Issue 6034 - :-abp-contains() accept a regular expression (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Address the regexp "escaping" Created Feb. 20, 2018, 5:49 p.m.
Right Patch Set: Some comments editing, Created Feb. 22, 2018, 2:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/common.js ('k') | test/browser/elemHideEmulation.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {escapeRegExp, filterToRegExp, splitSelector} = require("../common"); 20 const {textToRegExp, filterToRegExp, splitSelector} = require("../common");
21 21
22 let MIN_INVOCATION_INTERVAL = 3000; 22 let MIN_INVOCATION_INTERVAL = 3000;
23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; 23 const MAX_SYNCHRONOUS_PROCESSING_TIME = 50;
24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; 24 const abpSelectorRegexp = /:-abp-([\w-]+)\(/i;
25 25
26 /** Return position of node from parent. 26 /** Return position of node from parent.
27 * @param {Node} node the node to find the position of. 27 * @param {Node} node the node to find the position of.
28 * @return {number} One-based index like for :nth-child(), or 0 on error. 28 * @return {number} One-based index like for :nth-child(), or 0 on error.
29 */ 29 */
30 function positionInParent(node) 30 function positionInParent(node)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 { 170 {
171 return scopedQuerySelector(subtree, selector, true); 171 return scopedQuerySelector(subtree, selector, true);
172 } 172 }
173 173
174 const regexpRegexp = /^\/(.*)\/([im]*)$/; 174 const regexpRegexp = /^\/(.*)\/([im]*)$/;
175 175
176 /** 176 /**
177 * Make a regular expression from a text argument. If it can be parsed as a 177 * Make a regular expression from a text argument. If it can be parsed as a
178 * regular expression, parse it and the flags. 178 * regular expression, parse it and the flags.
179 * @param {string} text the text argument. 179 * @param {string} text the text argument.
180 * it overrides flags passed in the text argument.
Manish Jethani 2018/02/21 14:41:59 This line got left out.
hub 2018/02/21 21:38:01 Done.
181 * @return {?RegExp} a RegExp object or null in case of error. 180 * @return {?RegExp} a RegExp object or null in case of error.
182 */ 181 */
183 function makeRegExpParameter(text) 182 function makeRegExpParameter(text)
184 { 183 {
185 let flags; 184 let [, pattern, flags] =
186 let regexpString = null; 185 regexpRegexp.exec(text) || [undefined, textToRegExp(text)];
187 let match = regexpRegexp.exec(text);
188 if (match)
Manish Jethani 2018/02/21 14:41:59 So we're having a discussion on #eyeo-js about mod
Manish Jethani 2018/02/21 14:46:38 That spills over the 80 character line length, but
hub 2018/02/21 21:38:00 Done.
189 {
190 regexpString = match[1];
191 flags = match[2];
192 }
193 else
194 regexpString = escapeRegExp(text);
195 186
196 try 187 try
197 { 188 {
198 return new RegExp(regexpString, flags); 189 return new RegExp(pattern, flags);
199 } 190 }
200 catch (e) 191 catch (e)
201 { 192 {
202 } 193 }
203 return null; 194 return null;
204 } 195 }
205 196
206 function* evaluate(chain, index, prefix, subtree, styles) 197 function* evaluate(chain, index, prefix, subtree, styles)
207 { 198 {
208 if (index >= chain.length) 199 if (index >= chain.length)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 this._regexp = new RegExp(regexpString, "i"); 332 this._regexp = new RegExp(regexpString, "i");
342 } 333 }
343 334
344 PropsSelector.prototype = { 335 PropsSelector.prototype = {
345 preferHideWithSelector: true, 336 preferHideWithSelector: true,
346 dependsOnStyles: true, 337 dependsOnStyles: true,
347 338
348 *findPropsSelectors(styles, prefix, regexp) 339 *findPropsSelectors(styles, prefix, regexp)
349 { 340 {
350 for (let style of styles) 341 for (let style of styles)
351 if (regexp && regexp.test(style.style)) 342 if (regexp.test(style.style))
Manish Jethani 2018/02/21 14:41:59 This check is no longer necessary? (i.e. this._reg
hub 2018/02/21 21:38:00 Done.
352 for (let subSelector of style.subSelectors) 343 for (let subSelector of style.subSelectors)
353 { 344 {
354 if (subSelector.startsWith("*") && 345 if (subSelector.startsWith("*") &&
355 !incompletePrefixRegexp.test(prefix)) 346 !incompletePrefixRegexp.test(prefix))
356 { 347 {
357 subSelector = subSelector.substr(1); 348 subSelector = subSelector.substr(1);
358 } 349 }
359 let idx = subSelector.lastIndexOf("::"); 350 let idx = subSelector.lastIndexOf("::");
360 if (idx != -1) 351 if (idx != -1)
361 subSelector = subSelector.substr(0, idx); 352 subSelector = subSelector.substr(0, idx);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 characterData: true, 669 characterData: true,
679 subtree: true 670 subtree: true
680 } 671 }
681 ); 672 );
682 this.document.addEventListener("load", this.onLoad.bind(this), true); 673 this.document.addEventListener("load", this.onLoad.bind(this), true);
683 } 674 }
684 } 675 }
685 }; 676 };
686 677
687 exports.ElemHideEmulation = ElemHideEmulation; 678 exports.ElemHideEmulation = ElemHideEmulation;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld