diff --git a/changelog/15072.txt b/changelog/15072.txt new file mode 100644 index 000000000..c96b19469 --- /dev/null +++ b/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 +``` diff --git a/sdk/framework/field_data.go b/sdk/framework/field_data.go index eb7ffbbe2..99e3fb7ab 100644 --- a/sdk/framework/field_data.go +++ b/sdk/framework/field_data.go @@ -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, diff --git a/sdk/framework/field_data_test.go b/sdk/framework/field_data_test.go index 60ffa0823..d7cbd9761 100644 --- a/sdk/framework/field_data_test.go +++ b/sdk/framework/field_data_test.go @@ -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},