Skip to content

Commit 5ad8b6e

Browse files
committed
fix: reject empty value for comparison and matches operators
Empty values produced expressions like ${{ flow.name == "" }} which are technically valid but likely unintended. The exists operator correctly allows empty values since it takes no argument.
1 parent 6d0c7f5 commit 5ad8b6e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

internal/policywizard/forms.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,20 @@ func (m *Model) applyFormValues(fv formValues) {
383383
case "exists":
384384
m.storeSubExpr(policy.ExistsExpr(m.exprContext))
385385
case "matches":
386+
if fv.str == "" {
387+
m.validationErr = "regex pattern is required for matches"
388+
return
389+
}
386390
if err := validateRegex(fv.str); err != nil {
387391
m.validationErr = err.Error()
388392
return
389393
}
390394
m.storeSubExpr(policy.MatchesExpr(m.exprContext, fv.str))
391395
default:
396+
if fv.str == "" {
397+
m.validationErr = "value is required"
398+
return
399+
}
392400
m.storeSubExpr(policy.ComparisonExpr(m.exprContext, fv.operator, fv.str))
393401
}
394402

internal/policywizard/forms_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,28 @@ func TestApply_ExprCustomOp_SwitchOperatorClearsError(t *testing.T) {
454454
require.Len(t, m.pendingExprs, 1)
455455
}
456456

457+
func TestApply_ExprCustomOp_EmptyValueRejected(t *testing.T) {
458+
m := newTestModel()
459+
m.step = stepExprCustomOp
460+
m.exprContext = "flow.name"
461+
462+
m.applyFormValues(formValues{operator: "==", str: ""})
463+
464+
assert.Empty(t, m.pendingExprs)
465+
assert.Contains(t, m.validationErr, "value is required")
466+
}
467+
468+
func TestApply_ExprCustomOp_MatchesEmptyRegexRejected(t *testing.T) {
469+
m := newTestModel()
470+
m.step = stepExprCustomOp
471+
m.exprContext = "flow.name"
472+
473+
m.applyFormValues(formValues{operator: "matches", str: ""})
474+
475+
assert.Empty(t, m.pendingExprs)
476+
assert.Contains(t, m.validationErr, "regex pattern is required")
477+
}
478+
457479
func TestApply_ExprCustomOp_ExistsStoresPending(t *testing.T) {
458480
m := newTestModel()
459481
m.step = stepExprCustomOp

0 commit comments

Comments
 (0)