Skip to content

Commit

Permalink
bug: array form filed name should not contains bracket which led to i…
Browse files Browse the repository at this point in the history
…nvalid fieldname in ts codegen (#1706)
  • Loading branch information
Jinof authored Jan 16, 2024
1 parent 0fb6820 commit 76695ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion field_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down
22 changes: 22 additions & 0 deletions field_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 76695ca

Please sign in to comment.