From 594bfc256c4e1da1a6c9d335fa73a8f1d409e976 Mon Sep 17 00:00:00 2001 From: nityanandagohain Date: Mon, 1 Aug 2022 13:02:00 +0530 Subject: [PATCH] fulltext validation updated --- pkg/query-service/app/logs/parser.go | 6 +++--- pkg/query-service/app/logs/parser_test.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/query-service/app/logs/parser.go b/pkg/query-service/app/logs/parser.go index d709036cf3..103e959d4a 100644 --- a/pkg/query-service/app/logs/parser.go +++ b/pkg/query-service/app/logs/parser.go @@ -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") } } diff --git a/pkg/query-service/app/logs/parser_test.go b/pkg/query-service/app/logs/parser_test.go index cf8d12a803..df35ffbe80 100644 --- a/pkg/query-service/app/logs/parser_test.go +++ b/pkg/query-service/app/logs/parser_test.go @@ -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`,