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 --- content_scripts/mode_find.coffee | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/mode_find.coffee b/content_scripts/mode_find.coffee index 9b47cfbd..8c4286ae 100644 --- a/content_scripts/mode_find.coffee +++ b/content_scripts/mode_find.coffee @@ -132,10 +132,7 @@ class FindMode extends Mode # show a the number of results. We can grep on document.body.innerText, as it should be indistinguishable # from the internal representation used by window.find. else - # escape all special characters, so RegExp just parses the string 'as is'. - # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex - escapeRegExp = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g - parsedNonRegexQuery = @query.parsedQuery.replace(escapeRegExp, (char) -> "\\" + char) + parsedNonRegexQuery = Utils.escapeRegexSpecialCharacters @query.parsedQuery pattern = new RegExp(parsedNonRegexQuery, "g" + (if @query.ignoreCase then "i" else "")) text = document.body.innerText @query.matchCount = text.match(pattern)?.length -- cgit v1.2.3