Skip to content

Commit 0a8ac1a

Browse files
committed
fix: make UnwrapExpr tolerant of varying whitespace
Handle expressions like ${{expr}} (no inner spaces) in addition to the standard ${{ expr }} format.
1 parent 692dfa0 commit 0a8ac1a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

internal/policy/expression.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ func WrapExpr(raw string) string {
7070
}
7171

7272
// UnwrapExpr strips the ${{ }} wrapper, returning the inner expression.
73+
// Tolerates varying whitespace inside the delimiters.
7374
func UnwrapExpr(expr string) string {
74-
s := strings.TrimPrefix(expr, "${{ ")
75-
s = strings.TrimSuffix(s, " }}")
76-
return s
75+
s := strings.TrimSpace(expr)
76+
s = strings.TrimPrefix(s, "${{")
77+
s = strings.TrimSuffix(s, "}}")
78+
return strings.TrimSpace(s)
7779
}
7880

7981
// NegateExpr prefixes a raw (unwrapped) expression with the not operator.

internal/policy/expression_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func TestUnwrapExpr(t *testing.T) {
8383
assert.Equal(t, `flow.name == "prod"`, result)
8484
}
8585

86+
func TestUnwrapExpr_NoInnerSpaces(t *testing.T) {
87+
result := UnwrapExpr(`${{flow.name == "prod"}}`)
88+
assert.Equal(t, `flow.name == "prod"`, result)
89+
}
90+
8691
func TestUnwrapExpr_AlreadyRaw(t *testing.T) {
8792
result := UnwrapExpr(`flow.name == "prod"`)
8893
assert.Equal(t, `flow.name == "prod"`, result)

0 commit comments

Comments
 (0)