Fix empty link bug and proper error logging in highlightMentions.js (#12228)

* fix(chat) - Don't insert user link in url-less link and properly log source-mapping failures

* fix(chat) - Add link to markdown spec and list of known issues

* fix(chat) - Log regular expression as String
This commit is contained in:
Bart Enkelaar
2020-05-31 18:09:43 +02:00
committed by GitHub
parent 61d970db86
commit 1c00d7de5b
2 changed files with 34 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
import mongoose from 'mongoose';
import highlightMentions from '../../../../website/server/libs/highlightMentions';
describe('highlightMentions', () => {
@@ -101,12 +102,28 @@ describe('highlightMentions', () => {
expect(result[0]).to.equal('http://www.medium.com/@user/blog [@user](/profile/111)');
});
// https://spec.commonmark.org/0.29/#example-483
it('doesn\'t highlight user in a link without url', async () => {
const text = '[@user2]()';
const result = await highlightMentions(text);
expect(result[0]).to.equal(text);
});
// https://github.com/HabitRPG/habitica/issues/12217
it('doesn\'t highlight user in link with url-escapable characters', async () => {
const text = '[test](https://habitica.fandom.com/ru/@wiki/Снаряжение)';
const result = await highlightMentions(text);
expect(result[0]).to.equal(text);
});
// https://github.com/HabitRPG/habitica/issues/12223
it('matches a link in between two the same links', async () => {
const text = '[here](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)\n@user\n[hier](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)';
const result = await highlightMentions(text);
expect(result[0]).to.equal('[here](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)\n[@user](/profile/111)\n[hier](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)');
});
});
describe('exceptions in code blocks', () => {
@@ -149,14 +166,6 @@ describe('highlightMentions', () => {
expect(result[0]).to.equal('[@user](/profile/111) `@user`');
});
it('matches a link in between two the same links', async () => {
const text = '[here](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)\n@user\n[hier](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)';
const result = await highlightMentions(text);
expect(result[0]).to.equal('[here](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)\n[@user](/profile/111)\n[hier](http://habitica.wikia.com/wiki/The_Keep:Pirate_Cove/FAQ)');
});
});
it('github issue 12118, method crashes when square brackets are used', async () => {