mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
fix(chat) - graceful for failure and fix link regex (#12225)
* fix(chat) - graceful for failure and fix link regex * fix(chat) - Adjust unit test to test for the actual functional failure
This commit is contained in:
@@ -86,7 +86,7 @@ function toSourceMapRegex (token) {
|
||||
} else if (type === 'link_open') {
|
||||
const texts = token.textContents.map(escapeRegExp);
|
||||
regexStr = markup === 'linkify' || markup === 'autolink' ? texts[0]
|
||||
: `\\[.*${texts.join('.*')}.*\\]\\([^)]+\\)`;
|
||||
: `\\[[^\\]]*${texts.join('[^\\]]*')}[^\\]]*\\]\\([^)]+\\)`;
|
||||
} else {
|
||||
throw new Error(`No source mapping regex defined for ignore blocks of type ${type}`);
|
||||
}
|
||||
@@ -111,6 +111,11 @@ function findTextBlocks (text) {
|
||||
const targetText = text.substr(index);
|
||||
const match = targetText.match(regex);
|
||||
|
||||
if (!match) {
|
||||
// Should not happen, but insert to handle bugs gracefully
|
||||
return;
|
||||
}
|
||||
|
||||
if (match.index) {
|
||||
blocks.push({ text: targetText.substr(0, match.index), ignore: false });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user