Skip to content

Commit

Permalink
fix: include space before and or in utils.go (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: James <23193271+Jamess-Lucass@users.noreply.github.com>
  • Loading branch information
ArthurFreeb and Jamess-Lucass committed Mar 28, 2024
1 parent 7b935e5 commit dba289f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ type Base struct {
type User struct {
Base

Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Email string `json:"email"`
UserName string `gorm:"column:display_name" json:"userName"`
PersonSex string `json:"gender"`
Age uint `json:"age"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Email string `json:"email"`
UserName string `gorm:"column:display_name" json:"userName"`
PersonSex string `json:"gender"`
Age uint `json:"age"`
Contributor bool `json:"contributor"`
}

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -458,3 +459,18 @@ func Test_QueryWithFilterPropertyDoesntMatchJsonProperty(t *testing.T) {

assert.Equal(t, expectedSql, sql)
}

func Test_QueryWithFilterAndOrInColumnName(t *testing.T) {
query := Query{Filter: "contributor eq 'true'"}

sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
res, _, _ := Apply(tx.Model(&User{}), query, nil, nil, &[]User{})
return res.Find(&[]User{})
})

expectedSql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
return tx.Model(&User{}).Where("LOWER(contributor) = LOWER('true')").Find(&[]User{})
})

assert.Equal(t, expectedSql, sql)
}
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func splitString(input string) []string {
if char == '\'' {
buffer.WriteRune(rune(char))
singleQuote = !singleQuote
} else if !singleQuote && (char == 'a' || char == 'o') && i+1 < len(input) && (input[i:i+3] == "and" || input[i:i+2] == "or") {
} else if !singleQuote && (char == 'a' || char == 'o') && i+1 < len(input) && (input[i-1:i+3] == " and" || input[i-1:i+2] == " or") {
if buffer.Len() > 0 {
result = append(result, strings.TrimSpace(buffer.String()))
buffer.Reset()
Expand Down

0 comments on commit dba289f

Please sign in to comment.