[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:
Dean Whillier
2019-02-13 18:05:52 -05:00
committed by Miguel Alatzar
parent 317e3b14ab
commit 66cd2a98ac
2 changed files with 10 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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) {