From 018b4fece437af9600eda111ffbf4bffef243b7b Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 29 Jul 2020 13:51:19 -0700 Subject: [PATCH] typeahead_helper: Use _.escapeRegExp in build_highlight_regex. Signed-off-by: Anders Kaseorg --- static/js/typeahead_helper.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 6d29acf065..a4019933ea 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -1,4 +1,5 @@ const Handlebars = require("handlebars/runtime"); +const _ = require("lodash"); const pygments_data = require("../generated/pygments_data.json"); const emoji = require("../shared/js/emoji"); @@ -17,9 +18,7 @@ exports.get_cleaned_pm_recipients = function (query_string) { }; exports.build_highlight_regex = function (query) { - // the regex below is based on bootstrap code - query = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); - const regex = new RegExp("(" + query + ")", "ig"); + const regex = new RegExp("(" + _.escapeRegExp(query) + ")", "ig"); return regex; };