From c3f60d7ced72d274d960088bbf1a5b9ba3a6787b Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Fri, 6 Jan 2017 13:54:31 +0000 Subject: PLT-4791 Fix hashtag highlight in search results. (#4977) --- webapp/utils/text_formatting.jsx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'webapp/utils') diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx index 9f983a1ee..a18dd8627 100644 --- a/webapp/utils/text_formatting.jsx +++ b/webapp/utils/text_formatting.jsx @@ -452,6 +452,11 @@ export function highlightSearchTerms(text, tokens, searchPatterns) { output = output.replace(alias, newAlias); } + + // The pattern regexes are global, so calling pattern.test() above alters their + // state. Reset lastIndex to 0 between calls to test() to ensure it returns the + // same result every time it is called with the same value of token.originalText. + pattern.lastIndex = 0; } // the new tokens are stashed in a separate map since we can't add objects to a map during iteration -- cgit v1.2.3-1-g7c22