From bb11ab21ca8508762e5331b0fa95a6c6e72c0cf6 Mon Sep 17 00:00:00 2001 From: Dillen Padhiar <38965141+dpadhiar@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:37:31 -0800 Subject: [PATCH] fix: remove string replacement on expressions for event filtering (#1670) Signed-off-by: Dillen Padhiar --- common/expr/eval_test.go | 6 ++++++ eventsources/eventing.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/expr/eval_test.go b/common/expr/eval_test.go index bbb8ab043c..c03309957b 100644 --- a/common/expr/eval_test.go +++ b/common/expr/eval_test.go @@ -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) @@ -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) } diff --git a/eventsources/eventing.go b/eventsources/eventing.go index 8f7916f646..630ce54df2 100644 --- a/eventsources/eventing.go +++ b/eventsources/eventing.go @@ -565,5 +565,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) }