Skip to content

Commit a3e2c33

Browse files
committed
forbid ieq for boolean
1 parent 79a3be6 commit a3e2c33

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

example/example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestValidateFiltering(t *testing.T) {
4242
{`boolean_field in ["tRuE"]`, true},
4343
{`boolean_field=="True"`, false},
4444
{`boolean_field=="Blah"`, true},
45+
{`boolean_field:="True"`, true},
4546
}
4647

4748
for _, test := range tests {

options/validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func ValidateFiltering(f *query.Filtering, messageInfo map[string]FilteringOptio
5959
}
6060

6161
if fieldInfo.ValueType == QueryValidate_BOOL {
62+
63+
if x.Type != query.StringCondition_EQ {
64+
return fmt.Errorf("Operation %s is not allowed for %q", query.StringCondition_Type_name[int32(x.Type)], fieldTag)
65+
}
66+
6267
if _, err := strconv.ParseBool(x.Value); err != nil {
6368
return fmt.Errorf("Got invalid literal for field %q of type %s, expect 'true' or 'false'", fieldTag, fieldInfo.ValueType)
6469
}

plugin/plugin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
protoTypeInt64Value = ".google.protobuf.Int64Value"
3939
protoTypeUInt32Value = ".google.protobuf.UInt32Value"
4040
protoTypeUInt64Value = ".google.protobuf.UInt64Value"
41+
protoTypeBoolValue = ".google.protobuf.BoolValue"
4142
)
4243

4344
// QueryValidatePlugin implements the plugin interface and creates validations for collection operation parameters code from .protos
@@ -409,6 +410,8 @@ func (p *QueryValidatePlugin) getValueType(field *descriptor.FieldDescriptorProt
409410
protoTypeUInt32Value,
410411
protoTypeUInt64Value:
411412
return options.QueryValidate_NUMBER
413+
case protoTypeBoolValue:
414+
return options.QueryValidate_BOOL
412415
default:
413416
return options.QueryValidate_DEFAULT
414417
}
@@ -526,6 +529,7 @@ func (p *QueryValidatePlugin) getFieldSelectionDataAux(msg *generator.Descriptor
526529
protoTypeUUIDValue,
527530
protoTypeInet,
528531
protoTypeStringValue:
532+
case protoTypeBoolValue:
529533
case protoTypeDoubleValue,
530534
protoTypeFloatValue,
531535
protoTypeInt32Value,
@@ -589,7 +593,6 @@ func (p *QueryValidatePlugin) getDenyRules(fieldName string, opts *options.Query
589593
supportedOps = []options.QueryValidate_FilterOperator{
590594
options.QueryValidate_EQ,
591595
options.QueryValidate_IN,
592-
options.QueryValidate_IEQ,
593596
}
594597
}
595598

0 commit comments

Comments
 (0)