| Index: lib/content/elemHideEmulation.js |
| =================================================================== |
| --- a/lib/content/elemHideEmulation.js |
| +++ b/lib/content/elemHideEmulation.js |
| @@ -12,17 +12,17 @@ |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| "use strict"; |
| -const {filterToRegExp, splitSelector} = require("../common"); |
| +const {escapeRegExp, filterToRegExp, splitSelector} = require("../common"); |
| let MIN_INVOCATION_INTERVAL = 3000; |
| const MAX_SYNCHRONOUS_PROCESSING_TIME = 50; |
| const abpSelectorRegexp = /:-abp-([\w-]+)\(/i; |
| /** Return position of node from parent. |
| * @param {Node} node the node to find the position of. |
| * @return {number} One-based index like for :nth-child(), or 0 on error. |
| @@ -166,16 +166,48 @@ |
| subtree.querySelector(selector); |
| } |
| function scopedQuerySelectorAll(subtree, selector) |
| { |
| return scopedQuerySelector(subtree, selector, true); |
| } |
| +const regexpRegexp = /^\/(.*)\/([im]*)$/; |
| + |
| +/** |
| + * Make a regular expression from a text argument. If it can be parsed as a |
| + * regular expression, parse it and the flags. |
| + * @param {string} text the text argument. |
| + * 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.
|
| + * @return {?RegExp} a RegExp object or null in case of error. |
| + */ |
| +function makeRegExpParameter(text) |
| +{ |
| + let flags; |
| + let regexpString = null; |
| + let match = regexpRegexp.exec(text); |
| + 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.
|
| + { |
| + regexpString = match[1]; |
| + flags = match[2]; |
| + } |
| + else |
| + regexpString = escapeRegExp(text); |
| + |
| + try |
| + { |
| + return new RegExp(regexpString, flags); |
| + } |
| + catch (e) |
| + { |
| + } |
| + return null; |
| +} |
| + |
| function* evaluate(chain, index, prefix, subtree, styles) |
| { |
| if (index >= chain.length) |
| { |
| yield prefix; |
| return; |
| } |
| for (let [selector, element] of |
| @@ -258,17 +290,17 @@ |
| yield null; |
| } |
| } |
| } |
| }; |
| function ContainsSelector(textContent) |
| { |
| - this._text = textContent; |
| + this._regexp = makeRegExpParameter(textContent); |
| } |
| ContainsSelector.prototype = { |
| requiresHiding: true, |
| *getSelectors(prefix, subtree, stylesheet) |
| { |
| for (let element of this.getElements(prefix, subtree, stylesheet)) |
| @@ -280,17 +312,17 @@ |
| let actualPrefix = (!prefix || incompletePrefixRegexp.test(prefix)) ? |
| prefix + "*" : prefix; |
| let elements = scopedQuerySelectorAll(subtree, actualPrefix); |
| if (elements) |
| { |
| for (let element of elements) |
| { |
| - if (element.textContent.includes(this._text)) |
| + if (this._regexp && this._regexp.test(element.textContent)) |
| yield element; |
| else |
| yield null; |
| } |
| } |
| } |
| }; |
| @@ -311,17 +343,17 @@ |
| PropsSelector.prototype = { |
| preferHideWithSelector: true, |
| dependsOnStyles: true, |
| *findPropsSelectors(styles, prefix, regexp) |
| { |
| for (let style of styles) |
| - if (regexp.test(style.style)) |
| + if (regexp && 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.
|
| for (let subSelector of style.subSelectors) |
| { |
| if (subSelector.startsWith("*") && |
| !incompletePrefixRegexp.test(prefix)) |
| { |
| subSelector = subSelector.substr(1); |
| } |
| let idx = subSelector.lastIndexOf("::"); |