forked from Ivasoft/mattermost-mobile
[MM 13934] Prevent blank mention keys from crashing the app (#2570)
* don’t match blank word boundaries * test for blank mention keys * Check for blank mention before looking for match * account for multiple spaces as a blank mention
This commit is contained in:
committed by
Miguel Alatzar
parent
317e3b14ab
commit
66cd2a98ac
@@ -310,11 +310,15 @@ export function getFirstMention(str, mentionKeys) {
|
||||
let firstMentionIndex = -1;
|
||||
|
||||
for (const mention of mentionKeys) {
|
||||
if (mention.key.trim() === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const flags = mention.caseSensitive ? '' : 'i';
|
||||
const pattern = new RegExp(`\\b${escapeRegex(mention.key)}_*\\b`, flags);
|
||||
|
||||
const match = pattern.exec(str);
|
||||
if (!match) {
|
||||
if (!match || match[0] === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2758,6 +2758,11 @@ describe('Components.Markdown.transform', () => {
|
||||
input: 'apple banana orange',
|
||||
mentionKeys: [{key: '*\\3_.'}],
|
||||
expected: {index: -1, mention: null},
|
||||
}, {
|
||||
name: 'no blank mention keys',
|
||||
input: 'apple banana orange',
|
||||
mentionKeys: [{key: ''}],
|
||||
expected: {index: -1, mention: null},
|
||||
}];
|
||||
|
||||
for (const test of tests) {
|
||||
|
||||
Reference in New Issue
Block a user