From 1150786efd46778620a809f2d20b62ae1bf9a92a Mon Sep 17 00:00:00 2001 From: Lucas 'Paperboy' Rose-Winters Date: Wed, 22 Oct 2025 10:07:13 +1100 Subject: [PATCH] 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. --- src/systems/rendering/thoughts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/systems/rendering/thoughts.js b/src/systems/rendering/thoughts.js index 3d59c26..02f073c 100644 --- a/src/systems/rendering/thoughts.js +++ b/src/systems/rendering/thoughts.js @@ -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); }