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

Side by Side Diff: lib/common.js

Issue 29613805: Issue 6034 - :-abp-contains() accept a regular expression (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Address the regexp "escaping" Created Feb. 20, 2018, 5:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/content/elemHideEmulation.js » ('j') | lib/content/elemHideEmulation.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 20 /**
Manish Jethani 2018/02/21 14:41:59 I would call this function "textToRegExp" to match
hub 2018/02/21 21:38:00 Done.
21 * Escape string to match to be a regular expression string
22 * @param {string} s the string to search for.
23 * @return {string} regular expression representation of string match.
24 */
25 function escapeRegExp(s)
26 {
27 return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
28 }
29
30 exports.escapeRegExp = escapeRegExp;
31
32 /**
21 * Converts filter text into regular expression string 33 * Converts filter text into regular expression string
22 * @param {string} text as in Filter() 34 * @param {string} text as in Filter()
23 * @return {string} regular expression representation of filter text 35 * @return {string} regular expression representation of filter text
24 */ 36 */
25 function filterToRegExp(text) 37 function filterToRegExp(text)
26 { 38 {
27 return text 39 return text
28 // remove multiple wildcards 40 // remove multiple wildcards
29 .replace(/\*+/g, "*") 41 .replace(/\*+/g, "*")
30 // remove anchors following separator placeholder 42 // remove anchors following separator placeholder
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 start = i + 1; 94 start = i + 1;
83 } 95 }
84 } 96 }
85 } 97 }
86 98
87 selectors.push(selector.substring(start)); 99 selectors.push(selector.substring(start));
88 return selectors; 100 return selectors;
89 } 101 }
90 102
91 exports.splitSelector = splitSelector; 103 exports.splitSelector = splitSelector;
OLDNEW
« no previous file with comments | « no previous file | lib/content/elemHideEmulation.js » ('j') | lib/content/elemHideEmulation.js » ('J')

Powered by Google App Engine
This is Rietveld