summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-08-08 09:58:28 +0100
committerGitHub <noreply@github.com>2017-08-08 09:58:28 +0100
commita4ce7371ca132f52a446f29ef4d9d5adc61278da (patch)
tree2098d0e0ba18bd76aa40527faa4aaa9ca3168301
parentf4638aecec2933f20efb4b95c2e0a90c22b47b43 (diff)
downloadchat-a4ce7371ca132f52a446f29ef4d9d5adc61278da.tar.gz
chat-a4ce7371ca132f52a446f29ef4d9d5adc61278da.tar.bz2
chat-a4ce7371ca132f52a446f29ef4d9d5adc61278da.zip
Revert "PLT-6609: Don't highlight #hashtag.dot when searching for #hashtag (#7109)" (#7147)
This reverts commit f4638aecec2933f20efb4b95c2e0a90c22b47b43.
-rw-r--r--webapp/utils/markdown.jsx4
-rw-r--r--webapp/utils/text_formatting.jsx27
2 files changed, 7 insertions, 24 deletions
diff --git a/webapp/utils/markdown.jsx b/webapp/utils/markdown.jsx
index d424d9544..8733e6200 100644
--- a/webapp/utils/markdown.jsx
+++ b/webapp/utils/markdown.jsx
@@ -175,7 +175,7 @@ class MattermostMarkdownRenderer extends marked.Renderer {
if (this.formattingOptions.searchPatterns) {
for (const pattern of this.formattingOptions.searchPatterns) {
- if (pattern.pattern.test(href)) {
+ if (pattern.test(href)) {
output += ' search-highlight';
break;
}
@@ -189,7 +189,7 @@ class MattermostMarkdownRenderer extends marked.Renderer {
if (this.formattingOptions.siteURL) {
const pattern = new RegExp('^' + TextFormatting.escapeRegex(this.formattingOptions.siteURL) + '\\/(?:signup_user_complete|[^\\/]+\\/(?:pl|channels))\\/');
- internalLink = pattern.pattern.test(outHref);
+ internalLink = pattern.test(outHref);
}
if (internalLink) {
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 4602a31b2..33cc3242c 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -400,10 +400,7 @@ function convertSearchTermToRegex(term) {
pattern = '\\b()(' + escapeRegex(term) + ')\\b';
}
- return {
- pattern: new RegExp(pattern, 'gi'),
- term
- };
+ return new RegExp(pattern, 'gi');
}
export function highlightSearchTerms(text, tokens, searchPatterns) {
@@ -429,21 +426,7 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
// highlight existing tokens matching search terms
var newTokens = new Map();
for (const [alias, token] of tokens) {
- if (pattern.pattern.test(token.originalText)) {
- // If it's a Hashtag, skip it unless the search term is an exact match.
- let originalText = token.originalText;
- if (originalText.startsWith('#')) {
- originalText = originalText.substr(1);
- }
- let term = pattern.term;
- if (term.startsWith('#')) {
- term = term.substr(1);
- }
-
- if (alias.startsWith('$MM_HASHTAG') && originalText !== term) {
- continue;
- }
-
+ if (pattern.test(token.originalText)) {
const index = tokens.size + newTokens.size;
const newAlias = `$MM_SEARCHTERM${index}`;
@@ -455,10 +438,10 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
output = output.replace(alias, newAlias);
}
- // The pattern regexes are global, so calling pattern.pattern.test() above alters their
+ // 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.pattern.lastIndex = 0;
+ pattern.lastIndex = 0;
}
// the new tokens are stashed in a separate map since we can't add objects to a map during iteration
@@ -466,7 +449,7 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
tokens.set(newToken[0], newToken[1]);
}
- output = output.replace(pattern.pattern, replaceSearchTermWithToken);
+ output = output.replace(pattern, replaceSearchTermWithToken);
}
return output;