diff options
| author | mrmr1993 | 2015-09-11 13:26:31 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-09-11 13:26:31 +0100 |
| commit | ce2809a76e08780955198c11fc63eb990cd575cf (patch) | |
| tree | 49a07e27b9f87c07bc6986507e8187158f101b1e /lib | |
| parent | 4e5b82e3783bebe640ce98df4bd432da7640c69d (diff) | |
| download | vimium-ce2809a76e08780955198c11fc63eb990cd575cf.tar.bz2 | |
Move escaping regex special chars to its own utility function
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils.coffee | 6 |
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, "<").replace(/>/g, ">") # Generates a unique ID |
