From df9416d64cf103a3da4e484cac2ce428a1c82a95 Mon Sep 17 00:00:00 2001 From: Chris Capurso <1036769+ccapurso@users.noreply.github.com> Date: Mon, 18 Apr 2022 10:36:07 -0400 Subject: [PATCH 1/2] fix TypeCommaIntSlice panic caused by json.Number input --- sdk/framework/field_data.go | 6 ++++++ sdk/framework/field_data_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/sdk/framework/field_data.go b/sdk/framework/field_data.go index eb7ffbbe26f78..99e3fb7ab8888 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 60ffa08232f23..d7cbd976157ad 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}, From 8edb1c24505584230c71708f31be7cd7f392142d Mon Sep 17 00:00:00 2001 From: Chris Capurso <1036769+ccapurso@users.noreply.github.com> Date: Mon, 18 Apr 2022 10:45:24 -0400 Subject: [PATCH 2/2] add changelog entry --- changelog/15072.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/15072.txt diff --git a/changelog/15072.txt b/changelog/15072.txt new file mode 100644 index 0000000000000..c96b19469c712 --- /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 +```