From 1a4584f3dafbc2a81d44d667776cfa47fada7eaa Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 4 Nov 2015 09:56:27 -0500 Subject: Removed unused text formatting functions --- web/react/utils/text_formatting.jsx | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'web/react') diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index 2de858a17..c354941f7 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -64,22 +64,6 @@ export function doFormatText(text, options) { return output; } -export function doFormatEmoticons(text) { - const tokens = new Map(); - - let output = Emoticons.handleEmoticons(text, tokens); - output = replaceTokens(output, tokens); - - return output; -} - -export function doFormatMentions(text) { - const tokens = new Map(); - let output = autolinkAtMentions(text, tokens); - output = replaceTokens(output, tokens); - return output; -} - export function sanitizeHtml(text) { let output = text; -- cgit v1.2.3-1-g7c22 From f0823ba5d808086929274fe2f5f055264215f0f3 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 4 Nov 2015 09:57:02 -0500 Subject: Allowed @mentions to follow any non-alphanumeric character instead of just whitespace --- web/react/utils/text_formatting.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/react') diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index c354941f7..4d4849281 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -166,7 +166,7 @@ function autolinkAtMentions(text, tokens) { } let output = text; - output = output.replace(/(^|\s)(@([a-z0-9.\-_]*))/gi, replaceAtMentionWithToken); + output = output.replace(/(^|[^a-z0-9])(@([a-z0-9.\-_]*))/gi, replaceAtMentionWithToken); return output; } -- cgit v1.2.3-1-g7c22 From cfcfd3ebbb6380e9473557ad36b7a77c422cf3f0 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Wed, 4 Nov 2015 10:03:37 -0500 Subject: Properly escaped mention keywords and search terms when formatting them --- web/react/utils/text_formatting.jsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'web/react') 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) { -- cgit v1.2.3-1-g7c22