aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormrmr19932015-09-11 13:26:31 +0100
committermrmr19932015-09-11 13:26:31 +0100
commitce2809a76e08780955198c11fc63eb990cd575cf (patch)
tree49a07e27b9f87c07bc6986507e8187158f101b1e /lib
parent4e5b82e3783bebe640ce98df4bd432da7640c69d (diff)
downloadvimium-ce2809a76e08780955198c11fc63eb990cd575cf.tar.bz2
Move escaping regex special chars to its own utility function
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.coffee6
1 files changed, 6 insertions, 0 deletions
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, "&lt;").replace(/>/g, "&gt;")
# Generates a unique ID