Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extra computing to remove some special character before the expression is evaluated [SMG-336] #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ 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 = fmt.Sprintf("\"%v\"", sobj1)
default:
sobj1 = fmt.Sprintf("%v", obj1)
Expand All @@ -521,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)
Expand Down
50 changes: 50 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,56 @@ func TestParseWildcardConditionDifferentOf(t *testing.T) {
}
}

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 TestAdvancedParseWildcardCondition(t *testing.T) {
w := WildCardFilterSelection{Key: "@.context.releaseVersion == 'FCL-11 \" \" \\ \\ QAMLess'"}
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()
Expand Down