fix(chat) - issue 12586 - can't put links without titles in message boxes (#12594)

This commit is contained in:
Bart Enkelaar 2020-09-22 19:28:37 +02:00 committed by GitHub
parent 82be621850
commit 7c4faf8b7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View file

@ -171,28 +171,32 @@ describe('highlightMentions', () => {
it('github issue 12118, method crashes when square brackets are used', async () => {
const text = '[test]';
let err;
const result = await highlightMentions(text);
try {
await highlightMentions(text);
} catch (e) {
err = e;
}
expect(err).to.be.undefined;
expect(result[0]).to.equal(text);
});
it('github issue 12138, method crashes when regex chars are used in code block', async () => {
const text = '`[test]`';
let err;
const result = await highlightMentions(text);
try {
await highlightMentions(text);
} catch (e) {
err = e;
}
expect(result[0]).to.equal(text);
});
expect(err).to.be.undefined;
it('github issue 12586, method crashes when empty link is used', async () => {
const text = '[]()';
const result = await highlightMentions(text);
expect(result[0]).to.equal(text);
});
it('github issue 12586, method crashes when link without title is used', async () => {
const text = '[](www.google.com)';
const result = await highlightMentions(text);
expect(result[0]).to.equal(text);
});
});

View file

@ -94,7 +94,7 @@ function toSourceMapRegex (token) {
} else if (type === 'code_inline') {
regexStr = `${markup} ?${contentRegex} ?${markup}`;
} else if (type === 'link_open') {
const texts = token.textContents.map(escapeRegExp);
const texts = token.textContents ? token.textContents.map(escapeRegExp) : [''];
regexStr = markup === 'linkify' || markup === 'autolink' ? texts[0]
: `\\[[^\\]]*${texts.join('[^\\]]*')}[^\\]]*\\]\\([^)]*\\)`;
} else {