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

Unified Diff: lib/common.js

Issue 29613805: Issue 6034 - :-abp-contains() accept a regular expression (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Review comments Created Feb. 21, 2018, 9:37 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/content/elemHideEmulation.js » ('j') | lib/content/elemHideEmulation.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/common.js
===================================================================
--- a/lib/common.js
+++ b/lib/common.js
@@ -13,16 +13,28 @@
*
* 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";
/**
+ * Convert raw text into a regular expression string
Manish Jethani 2018/02/22 07:08:27 Sorry, for consistency, can we say "Converts" inst
hub 2018/02/22 14:07:49 Done.
+ * @param {string} text the string to convert.
Manish Jethani 2018/02/22 07:08:27 Nit: seems like we generally don't add periods at
hub 2018/02/22 14:07:49 Done.
+ * @return {string} regular expression representation of string match.
Manish Jethani 2018/02/22 07:08:28 "string match" seems to imply something, do you th
hub 2018/02/22 14:07:50 Done.
+ */
+function textToRegExp(text)
+{
+ return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
+}
+
+exports.textToRegExp = textToRegExp;
+
+/**
* Converts filter text into regular expression string
* @param {string} text as in Filter()
* @return {string} regular expression representation of filter text
*/
function filterToRegExp(text)
{
return text
// remove multiple wildcards
« 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