From 8b2b3412b1e9b7c191540e81e8b4cefab9ae79bb Mon Sep 17 00:00:00 2001 From: Abdillah MADI Date: Mon, 3 Jul 2023 15:20:10 +0200 Subject: [PATCH 1/4] feat: add extra computing to remove some special character before the expression is evaluated [SMG-336] --- parse.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parse.go b/parse.go index a96659e..5ada94e 100644 --- a/parse.go +++ b/parse.go @@ -513,6 +513,9 @@ func cmp_any(obj1, obj2 interface{}, op string) (bool, error) { switch obj1.(type) { case string: sobj1 = strings.ReplaceAll(obj1.(string), "'", "") + sobj1 = strings.ReplaceAll(sobj1, "\"", "") + sobj1 = strings.ReplaceAll(sobj1, "\\", "") + sobj1 = strings.ReplaceAll(sobj1, ".", "") sobj1 = fmt.Sprintf("\"%v\"", sobj1) default: sobj1 = fmt.Sprintf("%v", obj1) From cb5ce2e977552b1406ed4fef6828df215155526b Mon Sep 17 00:00:00 2001 From: Abdillah MADI Date: Mon, 3 Jul 2023 15:24:58 +0200 Subject: [PATCH 2/4] test: add unit test [SMG-336] --- parse_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/parse_test.go b/parse_test.go index 91fc573..a85c607 100644 --- a/parse_test.go +++ b/parse_test.go @@ -55,6 +55,57 @@ func TestParseWildcardConditionDifferentOf(t *testing.T) { } } +func TestParseWildcardConditionWithDotes(t *testing.T) { + w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} + + r := map[string]interface{}{ + "context": map[string]interface{}{ + "releaseVersion": "1.0.0", + }, + } + res, err := w.filter(r) + if err != nil { + t.Errorf("Error: %v", err) + } + if res == nil { + t.Errorf("filter() = nil; want true") + } +} + +func TestParseWildcardConditionWithBackslash(t *testing.T) { + w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} + + r := map[string]interface{}{ + "context": map[string]interface{}{ + "releaseVersion": "FCL-11 \\ \\ QAMLess", + }, + } + res, err := w.filter(r) + if err != nil { + t.Errorf("Error: %v", err) + } + if res == nil { + t.Errorf("filter() = nil; want true") + } +} + +func TestParseWildcardConditionWithDoubleQuotes(t *testing.T) { + w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} + + r := map[string]interface{}{ + "context": map[string]interface{}{ + "releaseVersion": "FCL-11 \" \" QAMLess", + }, + } + res, err := w.filter(r) + if err != nil { + t.Errorf("Error: %v", err) + } + if res == nil { + t.Errorf("filter() = nil; want true") + } +} + func TestGetConditionsFromKeySimple(t *testing.T) { w := WildCardFilterSelection{Key: "@.metadata.project_name != 'DEV-QA-WEB-BROWSER'"} conditions, err := w.GetConditionsFromKey() From e3e66d31466afcf1741014085b5dda584e2dfaef Mon Sep 17 00:00:00 2001 From: Abdillah MADI Date: Mon, 3 Jul 2023 16:39:52 +0200 Subject: [PATCH 3/4] feat: remove the replace on the dotes and apply the same computing on the right side expresion [SMG-336] --- parse.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 5ada94e..1ca848f 100644 --- a/parse.go +++ b/parse.go @@ -515,7 +515,6 @@ func cmp_any(obj1, obj2 interface{}, op string) (bool, error) { sobj1 = strings.ReplaceAll(obj1.(string), "'", "") sobj1 = strings.ReplaceAll(sobj1, "\"", "") sobj1 = strings.ReplaceAll(sobj1, "\\", "") - sobj1 = strings.ReplaceAll(sobj1, ".", "") sobj1 = fmt.Sprintf("\"%v\"", sobj1) default: sobj1 = fmt.Sprintf("%v", obj1) @@ -524,6 +523,8 @@ func cmp_any(obj1, obj2 interface{}, op string) (bool, error) { switch obj1.(type) { case string: sobj2 = strings.ReplaceAll(obj2.(string), "'", "") + sobj2 = strings.ReplaceAll(sobj2, "\"", "") + sobj2 = strings.ReplaceAll(sobj2, "\\", "") sobj2 = fmt.Sprintf("\"%v\"", sobj2) default: sobj2 = fmt.Sprintf("%v", obj2) From 664caab0d87d5e9f46b13ab32bf5eb31086fa125 Mon Sep 17 00:00:00 2001 From: Abdillah MADI Date: Mon, 3 Jul 2023 16:40:26 +0200 Subject: [PATCH 4/4] test: update the unit test [SMG-336] --- parse_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/parse_test.go b/parse_test.go index a85c607..022a4a3 100644 --- a/parse_test.go +++ b/parse_test.go @@ -55,12 +55,12 @@ func TestParseWildcardConditionDifferentOf(t *testing.T) { } } -func TestParseWildcardConditionWithDotes(t *testing.T) { +func TestParseWildcardConditionWithBackslash(t *testing.T) { w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} r := map[string]interface{}{ "context": map[string]interface{}{ - "releaseVersion": "1.0.0", + "releaseVersion": "FCL-11 \\ \\ QAMLess", }, } res, err := w.filter(r) @@ -72,12 +72,12 @@ func TestParseWildcardConditionWithDotes(t *testing.T) { } } -func TestParseWildcardConditionWithBackslash(t *testing.T) { +func TestParseWildcardConditionWithDoubleQuotes(t *testing.T) { w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} r := map[string]interface{}{ "context": map[string]interface{}{ - "releaseVersion": "FCL-11 \\ \\ QAMLess", + "releaseVersion": "FCL-11 \" \" QAMLess", }, } res, err := w.filter(r) @@ -89,12 +89,11 @@ func TestParseWildcardConditionWithBackslash(t *testing.T) { } } -func TestParseWildcardConditionWithDoubleQuotes(t *testing.T) { - w := WildCardFilterSelection{Key: "@.context.releaseVersion != ''"} - +func TestAdvancedParseWildcardCondition(t *testing.T) { + w := WildCardFilterSelection{Key: "@.context.releaseVersion == 'FCL-11 \" \" \\ \\ QAMLess'"} r := map[string]interface{}{ "context": map[string]interface{}{ - "releaseVersion": "FCL-11 \" \" QAMLess", + "releaseVersion": "FCL-11 \" \" \\ \\ QAMLess", }, } res, err := w.filter(r)