🐛 Improve invalid regex handling in comparison logic

This commit is contained in:
Baptiste Arnaud 2025-05-28 15:31:34 +02:00
parent 45f7e2ca5e
commit 78a1ce26f9
No known key found for this signature in database

View File

@ -12,7 +12,7 @@ export const executeCondition = (
sessionStore,
variables,
}: { sessionStore: SessionStore; variables: Variable[] },
): boolean => {
): { passed: boolean; logs?: ContinueChatResponse["logs"] } => {
if (!condition.comparisons || condition.comparisons.length === 0)
return false;
return (condition.logicalOperator ?? LogicalOperator.AND) ===
@ -178,7 +178,12 @@ const executeComparison = (
if (b === "" || !b || !a) return false;
const regex = preprocessRegex(b);
if (!regex.pattern) return false;
return new RegExp(regex.pattern, regex.flags).test(a);
try {
return new RegExp(regex.pattern, regex.flags).test(a);
} catch {
// Most likelInvalid regex, treat as non-match
return false;
}
};
return compare(matchesRegex, inputValue, value, "some");
}