Skip to content

Commit

Permalink
fix: remove string replacement on expressions for event filtering (ar…
Browse files Browse the repository at this point in the history
…goproj#1670)

Signed-off-by: Dillen Padhiar <dpadhiar99@gmail.com>
  • Loading branch information
dpadhiar authored and BulkBeing committed Mar 7, 2022
1 parent 84aa42f commit 411c026
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions common/expr/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestEvalBool(t *testing.T) {
"email": "johndoe@intuit.com",
"gender": "Male",
"dept": "devp",
"uuid": "test-case-hyphen",
}

pass, err := EvalBool("(id == 1) && (last_name == 'Doe')", env)
Expand All @@ -54,4 +55,9 @@ func TestEvalBool(t *testing.T) {
pass, err = EvalBool("invalidexpression", env)
assert.Error(t, err)
assert.False(t, pass)

// expr with '-' evaluate the same as others
pass, err = EvalBool("(uuid == 'test-case-hyphen')", env)
assert.NoError(t, err)
assert.True(t, pass)
}
2 changes: 1 addition & 1 deletion eventsources/eventing.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,5 +573,5 @@ func filterEvent(data []byte, filter *v1alpha1.EventSourceFilter) (bool, error)
params[strings.ReplaceAll(key, "-", "_")] = value
}
env := expr.GetFuncMap(params)
return expr.EvalBool(strings.ReplaceAll(filter.Expression, "-", "_"), env)
return expr.EvalBool(filter.Expression, env)
}

0 comments on commit 411c026

Please sign in to comment.