diff --git a/field_parser.go b/field_parser.go index 98ad0ddc7..faaa53ec9 100644 --- a/field_parser.go +++ b/field_parser.go @@ -98,7 +98,7 @@ func (ps *tagBaseFieldParser) FieldName() (string, error) { func (ps *tagBaseFieldParser) FormName() string { if ps.field.Tag != nil { - return strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0]) + return strings.TrimRight(strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0]), "[]") } return "" } diff --git a/field_parser_test.go b/field_parser_test.go index a7487c03d..391b28199 100644 --- a/field_parser_test.go +++ b/field_parser_test.go @@ -668,4 +668,26 @@ func TestValidTags(t *testing.T) { assert.NoError(t, err) assert.Empty(t, schema.Enum) }) + + t.Run("Form Filed Name", func(t *testing.T) { + t.Parallel() + + filedname, err := newTagBaseFieldParser( + &Parser{}, + &ast.Field{Tag: &ast.BasicLit{ + Value: `form:"test[]"`, + }}, + ).FieldName() + assert.NoError(t, err) + assert.Equal(t, "test", filedname) + + filedname, err = newTagBaseFieldParser( + &Parser{}, + &ast.Field{Tag: &ast.BasicLit{ + Value: `form:"test"`, + }}, + ).FieldName() + assert.NoError(t, err) + assert.Equal(t, "test", filedname) + }) }