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:
@@ -151,7 +151,8 @@ function cmdStateUpdate(cwd, field, value) {
|
|||||||
// ─── State Progression Engine ────────────────────────────────────────────────
|
// ─── State Progression Engine ────────────────────────────────────────────────
|
||||||
|
|
||||||
function stateExtractField(content, fieldName) {
|
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);
|
const match = content.match(pattern);
|
||||||
return match ? match[1].trim() : null;
|
return match ? match[1].trim() : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user