Skip to content

Commit f4226b8

Browse files
committed
fix: guard CombineExprs against zero args
1 parent c83ccd9 commit f4226b8

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

internal/policy/expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func ComparisonExpr(context, op, value string) string {
5555

5656
// CombineExprs joins inner expressions (without ${{ }} wrappers) with a logical operator.
5757
func CombineExprs(op string, exprs ...string) string {
58+
if len(exprs) == 0 {
59+
return ""
60+
}
5861
if len(exprs) == 1 {
5962
return WrapExpr(exprs[0])
6063
}

internal/policy/expression_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func TestCombineExprs_Single(t *testing.T) {
6868
assert.Equal(t, `${{ flow.name == "prod" }}`, result)
6969
}
7070

71+
func TestCombineExprs_Empty(t *testing.T) {
72+
result := CombineExprs("and")
73+
assert.Equal(t, "", result)
74+
}
75+
7176
func TestWrapExpr_AddsWrapper(t *testing.T) {
7277
result := WrapExpr(`flow.name == "prod"`)
7378
assert.Equal(t, `${{ flow.name == "prod" }}`, result)

0 commit comments

Comments
 (0)