Skip to content

Commit

Permalink
fix replaceAndOr()
Browse files Browse the repository at this point in the history
  • Loading branch information
hengwei-test committed May 16, 2024
1 parent 638dc69 commit 112b5c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/xml_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func replaceAndOr(s string) string {
c := runes[i]
// fmt.Println("****", s, " pos ", string(c))
switch c {
case '"':
case '"':
if inSingleStr {
} else if inDoubleStr {
if isEscaping {
Expand Down Expand Up @@ -600,7 +600,7 @@ func replaceAndOr(s string) string {
}
}
default:
if unicode.IsSpace(c) {
if !isEscaping && !inSingleStr && !inDoubleStr && unicode.IsSpace(c) {
if or_index == 2 {
sb.WriteString("||")
} else {
Expand Down
10 changes: 10 additions & 0 deletions core/xml_expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ func TestReplaceAndOr(t *testing.T) {
txt: "a \"lte\" lte b",
result: "a \"lte\" <= b",
},

{
txt: "abc = \" a=b and c = 2 or a gt c or a lt b and a gte 9 or c lte 10 \"",
result: "abc = \" a=b and c = 2 or a gt c or a lt b and a gte 9 or c lte 10 \"",
},

{
txt: "abc = ' a=b and c = 2 or a gt c or a lt b and a gte 9 or c lte 10 '",
result: "abc = ' a=b and c = 2 or a gt c or a lt b and a gte 9 or c lte 10 '",
},
} {
s := replaceAndOr(test.txt)
if s != test.result {
Expand Down

0 comments on commit 112b5c0

Please sign in to comment.