fulltext validation updated

This commit is contained in:
nityanandagohain 2022-08-01 13:02:00 +05:30
parent 5894acdb2d
commit 594bfc256c
2 changed files with 8 additions and 3 deletions

View File

@ -32,7 +32,7 @@ const (
IDEND = "idEnd"
)
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?|or( )*?)?(([\w.-]+ (in|nin) \([\S ]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) (')?[^']+(')?)`)
var tokenRegex, _ = regexp.Compile(`(?i)(and( )*?|or( )*?)?(([\w.-]+ (in|nin) \([^(]+\))|([\w.]+ (gt|lt|gte|lte) (')?[\S]+(')?)|([\w.]+ (contains|ncontains)) '[^']+')`)
var operatorRegex, _ = regexp.Compile(`(?i)(?: )(in|nin|gt|lt|gte|lte|contains|ncontains)(?: )`)
func ParseLogFilterParams(r *http.Request) (*model.LogsFilterParams, error) {
@ -204,7 +204,7 @@ func parseColumn(s string) (*string, error) {
return nil, fmt.Errorf("incorrect filter")
}
if strings.HasPrefix(s, AND) {
if strings.HasPrefix(s, AND) || strings.HasPrefix(s, OR) {
colName = filter[1]
} else {
colName = filter[0]
@ -237,7 +237,7 @@ func replaceInterestingFields(allFields *model.GetFieldsResponse, queryTokens []
if _, ok := selectedFieldsLookup[*col]; !ok && *col != "body" {
if field, ok := interestingFieldLookup[*col]; ok {
sqlColName = fmt.Sprintf("%s_%s_value[indexOf(%s_%s_key, '%s')]", field.Type, strings.ToLower(field.DataType), field.Type, strings.ToLower(field.DataType), *col)
} else {
} else if strings.Compare(strings.ToLower(*col), "fulltext") != 0 {
return nil, fmt.Errorf("field not found for filtering")
}
}

View File

@ -42,6 +42,11 @@ var correctQueriesTest = []struct {
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
},
{
"mixing and or",
`id in ('2CkBCauK8m3nkyKR19YhCw6WbdY') and id in ('2CkBCauK8m3nkyKR19YhCw6WbdY','2CkBCauK8m3nkyKR19YhCw6WbdY') or fulltext contains 'OPTIONS /api/v1/logs'`,
[]string{`id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY') `, `and id IN ('2CkBCauK8m3nkyKR19YhCw6WbdY','2CkBCauK8m3nkyKR19YhCw6WbdY') `, `OR body ILIKE '%OPTIONS /api/v1/logs%' `},
},
{
`filters with lt,gt,lte,gte operators`,
`id lt 100 and id gt 50 and code lte 500 and code gte 400`,