Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATLAS-13592: adding regex validation #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13.0-alpine AS builder
FROM golang:1.16.0-alpine AS builder

LABEL stage=server-intermediate

Expand Down
4 changes: 4 additions & 0 deletions example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestValidateFiltering(t *testing.T) {
{`boolean_field=="True"`, false},
{`boolean_field=="Blah"`, true},
{`boolean_field:="True"`, true},
{`first_name~".*Sam"`, false},
{`first_name~"*Sam"`, true},
{`first_name~"*Sam" and sure_name~"*Samuelson"`, true},
{`first_name~"Sam" and sure_name~"*Samuelson"`, true},
}

for _, test := range tests {
Expand Down
8 changes: 8 additions & 0 deletions options/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package options

import (
"fmt"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -58,6 +59,13 @@ func ValidateFiltering(f *query.Filtering, messageInfo map[string]FilteringOptio
return fmt.Errorf("Got invalid literal type for %s, expect %s", fieldTag, fieldInfo.ValueType)
}

if fieldInfo.ValueType == QueryValidate_STRING {
v := x.GetValue()
if _, err := regexp.Compile(v); err != nil {
return fmt.Errorf("incorrect regex %q in field %q %w", v, fieldTag, err)
}
}

if fieldInfo.ValueType == QueryValidate_BOOL {

if x.Type != query.StringCondition_EQ {
Expand Down