fix: escape regex metacharacters in stateExtractField (#741)

stateReplaceField properly escaped fieldName before building the regex,
but stateExtractField did not. Field names containing regex metacharacters
could cause incorrect matches or regex errors.

Co-authored-by: Ethan Hurst <ethan.hurst@outlook.com.au>
This commit is contained in:
Ethan Hurst
2026-02-27 18:58:55 +00:00
committed by GitHub
parent 31c8a91ee4
commit ff3e2fd5eb

View File

@@ -151,7 +151,8 @@ function cmdStateUpdate(cwd, field, value) {
// ─── State Progression Engine ────────────────────────────────────────────────
function stateExtractField(content, fieldName) {
const pattern = new RegExp(`\\*\\*${fieldName}:\\*\\*\\s*(.+)`, 'i');
const escaped = fieldName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const pattern = new RegExp(`\\*\\*${escaped}:\\*\\*\\s*(.+)`, 'i');
const match = content.match(pattern);
return match ? match[1].trim() : null;
}