diff --git a/dtos/reading.go b/dtos/reading.go index 8d30acfe..bcaac836 100644 --- a/dtos/reading.go +++ b/dtos/reading.go @@ -407,9 +407,10 @@ func parseSimpleValue(valueType string, value string) (err error) { } func parseArrayValue(valueType string, value string) (err error) { - arrayValue := strings.Split(value[1:len(value)-1], ", ") // trim "[" and "]" + arrayValue := strings.Split(value[1:len(value)-1], ",") // trim "[" and "]" for _, v := range arrayValue { + v = strings.TrimSpace(v) switch valueType { case common.ValueTypeBoolArray: err = parseSimpleValue(common.ValueTypeBool, v) diff --git a/dtos/reading_test.go b/dtos/reading_test.go index 95c66c0c..3451e98b 100644 --- a/dtos/reading_test.go +++ b/dtos/reading_test.go @@ -276,6 +276,30 @@ func TestValidateValue(t *testing.T) { } } +func TestValidateArrayValue(t *testing.T) { + tests := []struct { + name string + valueType string + value string + expectError bool + }{ + {"Valid separator (comma followed by a space)", common.ValueTypeBoolArray, "[true, false]", false}, + {"Valid separator (comma)", common.ValueTypeBoolArray, "[true,false]", false}, + {"Invalid separator", common.ValueTypeBoolArray, "[true@false]", true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateValue(tt.valueType, tt.value) + if tt.expectError { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} + func TestValidateValueError(t *testing.T) { invalidValue := "invalid" tests := []struct {