Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-12838: Make hashtag highlighting case insensitive. (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
grundleborg committed Nov 1, 2018
1 parent 734803e commit 94b41df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/utils/text_formatting.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {highlightSearchTerms} from 'utils/text_formatting.jsx';

describe('highlightSearchTerms', () => {
test('hashtags should highlight case-insensitively', () => {
const text = '$MM_HASHTAG0$';
const tokens = new Map(
[['$MM_HASHTAG0$', {
hashtag: 'Test',
originalText: '#Test',
value: '<a class="mention-link" href="#" data-hashtag="#Test">#Test</a>',
}]],
);
const searchPatterns = [
{
pattern: /(\W|^)(#test)\b/gi,
term: '#test',
},
];

const output = highlightSearchTerms(text, tokens, searchPatterns);
expect(output).toBe('$MM_SEARCHTERM1$');
expect(tokens.get('$MM_SEARCHTERM1$').value).toBe('<span class="search-highlight">$MM_HASHTAG0$</span>');
});
});
2 changes: 1 addition & 1 deletion utils/text_formatting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export function highlightSearchTerms(text, tokens, searchPatterns) {
term = term.substr(1);
}

if (alias.startsWith('$MM_HASHTAG') && alias.endsWith('$') && originalText !== term) {
if (alias.startsWith('$MM_HASHTAG') && alias.endsWith('$') && originalText.toLowerCase() !== term.toLowerCase()) {
continue;
}

Expand Down

0 comments on commit 94b41df

Please sign in to comment.