fix: escape special regex characters in namesMatch function

Character names containing regex special chars (like brackets) were
causing 'Invalid regular expression' errors when building character
thoughts HTML. Now properly escapes characters before RegExp creation.
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-10-22 10:07:13 +11:00
parent 5ac034438c
commit 1150786efd
+3 -1
View File
@@ -51,7 +51,9 @@ function namesMatch(cardName, aiName) {
if (cardCore === aiCore) return true;
// 3. Check if card name appears as complete word in AI name
const wordBoundary = new RegExp(`\\b${cardCore}\\b`);
// Escape special regex characters to prevent "Invalid regular expression" errors
const escapedCardCore = cardCore.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const wordBoundary = new RegExp(`\\b${escapedCardCore}\\b`);
return wordBoundary.test(aiCore);
}