Skip to content

Commit

Permalink
Added rules to handle specialCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
grrlopes committed Aug 13, 2023
1 parent e79b179 commit 600fc55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion helper/parsefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package helper
import "strings"

func ParseFilter(filter string) string {
var addQuotes []string

filter = strings.ReplaceAll(filter, "\"", "'")

trim := strings.TrimSpace(filter)

split := strings.Split(trim, " ")

join := strings.Join(split, "* AND ")
for _, v := range split {
addQuotes = append(addQuotes, `"`+v+`"`)
}

join := strings.Join(addQuotes, "* AND ")

join += "* AND"

Expand Down
4 changes: 2 additions & 2 deletions repositories/sqlite/sqliterepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (sql *SQLiteRepository) Search(filter string, limit int, skip int) ([]entit
result *gorm.DB
)

if filter == "*" {
if filter == `""*` {
result = sql.database.Limit(limit).Offset(skip).Where("cmd LIKE ?", "%"+""+"%").Find(&commands)
} else {
result = sql.database.Raw(
Expand All @@ -105,7 +105,7 @@ func (sql *SQLiteRepository) SearchCount(filter string) (int, error) {
err error
)

if filter == "*" {
if filter == `""*` {
err = sql.database.Model(&command).Where("cmd LIKE ?", "%"+""+"%").Count(&count).Error
countResult = int(count)
} else {
Expand Down

0 comments on commit 600fc55

Please sign in to comment.