Skip to content

Commit 102baf6

Browse files
Copilothotlong
andcommitted
Address code review feedback: improve expression parser robustness
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 18dbca5 commit 102baf6

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

packages/core/src/validation/validators/object-validation-engine.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,17 @@ class SimpleExpressionEvaluator implements ValidationExpressionEvaluator {
147147

148148
switch (op) {
149149
case '===':
150-
case '==': return leftVal == rightVal;
150+
return leftVal === rightVal;
151+
case '==':
152+
// Use loose equality for backward compatibility with existing expressions
153+
// eslint-disable-next-line eqeqeq
154+
return leftVal == rightVal;
151155
case '!==':
152-
case '!=': return leftVal != rightVal;
156+
return leftVal !== rightVal;
157+
case '!=':
158+
// Use loose inequality for backward compatibility with existing expressions
159+
// eslint-disable-next-line eqeqeq
160+
return leftVal != rightVal;
153161
case '>': return leftVal > rightVal;
154162
case '<': return leftVal < rightVal;
155163
case '>=': return leftVal >= rightVal;
@@ -175,11 +183,14 @@ class SimpleExpressionEvaluator implements ValidationExpressionEvaluator {
175183
for (let i = 0; i < expr.length; i++) {
176184
const char = expr[i];
177185
const nextChar = expr[i + 1];
186+
const prevChar = i > 0 ? expr[i - 1] : '';
178187

188+
// Handle string quotes, checking for escape sequences
179189
if ((char === '"' || char === "'") && !inString) {
180190
inString = true;
181191
stringChar = char;
182-
} else if (char === stringChar && inString) {
192+
} else if (char === stringChar && inString && prevChar !== '\\') {
193+
// Only close string if quote is not escaped
183194
inString = false;
184195
}
185196

0 commit comments

Comments
 (0)