Skip to content

Commit 76695ca

Browse files
authoredJan 16, 2024
bug: array form filed name should not contains bracket which led to invalid fieldname in ts codegen (#1706)
1 parent 0fb6820 commit 76695ca

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎field_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (ps *tagBaseFieldParser) FieldName() (string, error) {
9898

9999
func (ps *tagBaseFieldParser) FormName() string {
100100
if ps.field.Tag != nil {
101-
return strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0])
101+
return strings.TrimRight(strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0]), "[]")
102102
}
103103
return ""
104104
}

‎field_parser_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,26 @@ func TestValidTags(t *testing.T) {
668668
assert.NoError(t, err)
669669
assert.Empty(t, schema.Enum)
670670
})
671+
672+
t.Run("Form Filed Name", func(t *testing.T) {
673+
t.Parallel()
674+
675+
filedname, err := newTagBaseFieldParser(
676+
&Parser{},
677+
&ast.Field{Tag: &ast.BasicLit{
678+
Value: `form:"test[]"`,
679+
}},
680+
).FieldName()
681+
assert.NoError(t, err)
682+
assert.Equal(t, "test", filedname)
683+
684+
filedname, err = newTagBaseFieldParser(
685+
&Parser{},
686+
&ast.Field{Tag: &ast.BasicLit{
687+
Value: `form:"test"`,
688+
}},
689+
).FieldName()
690+
assert.NoError(t, err)
691+
assert.Equal(t, "test", filedname)
692+
})
671693
}

0 commit comments

Comments
 (0)
Please sign in to comment.