From ce2809a76e08780955198c11fc63eb990cd575cf Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Fri, 11 Sep 2015 13:26:31 +0100 Subject: Move escaping regex special chars to its own utility function --- lib/utils.coffee | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/utils.coffee b/lib/utils.coffee index 90469fad..e0b9ba36 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -19,6 +19,12 @@ Utils = func = obj[components.pop()] func.apply(obj, argArray) + # Escape all special characters, so RegExp will parse the string 'as is'. + # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex + escapeRegexSpecialCharacters: do -> + escapeRegex = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g + (str) -> str.replace escapeRegex, "\\$&" + escapeHtml: (string) -> string.replace(//g, ">") # Generates a unique ID -- cgit v1.2.3