Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TypeCommaIntSlice panic caused by json.Number input #15072

Merged
merged 2 commits into from Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/15072.txt
@@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic caused by parsing JSON integers for fields defined as comma-delimited integers
```
6 changes: 6 additions & 0 deletions sdk/framework/field_data.go
Expand Up @@ -243,6 +243,12 @@ func (d *FieldData) getPrimitive(k string, schema *FieldSchema) (interface{}, bo

case TypeCommaIntSlice:
var result []int

jsonIn, ok := raw.(json.Number)
if ok {
raw = jsonIn.String()
}

config := &mapstructure.DecoderConfig{
Result: &result,
WeaklyTypedInput: true,
Expand Down
13 changes: 13 additions & 0 deletions sdk/framework/field_data_test.go
Expand Up @@ -593,6 +593,19 @@ func TestFieldDataGet(t *testing.T) {
[]int{},
false,
},

"comma int slice type, json number": {
map[string]*FieldSchema{
"foo": {Type: TypeCommaIntSlice},
},
map[string]interface{}{
"foo": json.Number("1"),
},
"foo",
[]int{1},
false,
},

"name string type, valid string": {
map[string]*FieldSchema{
"foo": {Type: TypeNameString},
Expand Down