Fix letter replacement regex — only rewrite 'Both X and Y' patterns, not standalone letters in answer text

This commit is contained in:
Justin Oros
2026-05-14 16:12:15 -07:00
parent 9676257668
commit f0585c30c3
+11 -2
View File
@@ -1088,8 +1088,17 @@ class Game {
});
function rewriteLetterRefs(text) {
return text.replace(/\b([ABCD])\b/g, (match, letter) => {
return letterToSlot[letter] !== undefined ? letterToSlot[letter] : match;
/* Only rewrite letters that appear in explicit option-reference patterns:
"Both A and B", "A and B", "Both B and C", etc.
Never replace standalone A/B/C/D in regular sentence text. */
return text.replace(/\bBoth ([ABCD]) and ([ABCD])\b/gi, (_, l1, l2) => {
const n1 = letterToSlot[l1.toUpperCase()];
const n2 = letterToSlot[l2.toUpperCase()];
return `Both ${n1 ?? l1} and ${n2 ?? l2}`;
}).replace(/\b([ABCD]) and ([ABCD])\b/g, (_, l1, l2) => {
const n1 = letterToSlot[l1];
const n2 = letterToSlot[l2];
return `${n1 ?? l1} and ${n2 ?? l2}`;
});
}