summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-11-04 10:03:37 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-11-04 10:03:37 -0500
commitcfcfd3ebbb6380e9473557ad36b7a77c422cf3f0 (patch)
tree672f2ba1a9e4ed8423b5af2bdadc29853b6bfee8 /web/react/utils
parentf0823ba5d808086929274fe2f5f055264215f0f3 (diff)
downloadchat-cfcfd3ebbb6380e9473557ad36b7a77c422cf3f0.tar.gz
chat-cfcfd3ebbb6380e9473557ad36b7a77c422cf3f0.tar.bz2
chat-cfcfd3ebbb6380e9473557ad36b7a77c422cf3f0.zip
Properly escaped mention keywords and search terms when formatting them
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/text_formatting.jsx8
1 files changed, 6 insertions, 2 deletions
diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx
index 4d4849281..ac26107cc 100644
--- a/web/react/utils/text_formatting.jsx
+++ b/web/react/utils/text_formatting.jsx
@@ -171,6 +171,10 @@ function autolinkAtMentions(text, tokens) {
return output;
}
+function escapeRegex(text) {
+ return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+}
+
function highlightCurrentMentions(text, tokens) {
let output = text;
@@ -210,7 +214,7 @@ function highlightCurrentMentions(text, tokens) {
}
for (const mention of UserStore.getCurrentMentionKeys()) {
- output = output.replace(new RegExp(`(^|\\W)(${mention})\\b`, 'gi'), replaceCurrentMentionWithToken);
+ output = output.replace(new RegExp(`(^|\\W)(${escapeRegex(mention)})\\b`, 'gi'), replaceCurrentMentionWithToken);
}
return output;
@@ -290,7 +294,7 @@ function highlightSearchTerm(text, tokens, searchTerm) {
return prefix + alias;
}
- return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken);
+ return output.replace(new RegExp(`()(${escapeRegex(searchTerm)})`, 'gi'), replaceSearchTermWithToken);
}
function replaceTokens(text, tokens) {