http get方法 url 参数带中括号 (#1226)

* fix url query array problem

* use TrimSuffix
pull/1235/head
zwhyb 3 years ago committed by GitHub
parent 77d2cfb653
commit d4ac341bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      encoding/form/proto_decode.go

@ -36,9 +36,10 @@ func populateFieldValues(v protoreflect.Message, fieldPath []string, values []st
var fd protoreflect.FieldDescriptor
for i, fieldName := range fieldPath {
fields := v.Descriptor().Fields()
if fd = fields.ByName(protoreflect.Name(fieldName)); fd == nil {
fd = fields.ByJSONName(fieldName)
if fd = getDescriptorByFieldAndName(fields, fieldName); fd == nil {
if len(fieldName) > 2 && strings.HasSuffix(fieldName, "[]") {
fd = getDescriptorByFieldAndName(fields, strings.TrimSuffix(fieldName, "[]"))
}
if fd == nil {
// ignore unexpected field.
return nil
@ -72,6 +73,17 @@ func populateFieldValues(v protoreflect.Message, fieldPath []string, values []st
return populateField(fd, v, values[0])
}
func getDescriptorByFieldAndName(fields protoreflect.FieldDescriptors, fieldName string) protoreflect.FieldDescriptor {
var fd protoreflect.FieldDescriptor
if fd = fields.ByName(protoreflect.Name(fieldName)); fd == nil {
fd = fields.ByJSONName(fieldName)
if fd == nil {
return nil
}
}
return fd
}
func populateField(fd protoreflect.FieldDescriptor, v protoreflect.Message, value string) error {
val, err := parseField(fd, value)
if err != nil {

Loading…
Cancel
Save