diff --git a/lib/map_walker.go b/lib/map_walker.go index 95827a0ee..ca103806d 100644 --- a/lib/map_walker.go +++ b/lib/map_walker.go @@ -34,6 +34,7 @@ func MapWalk(input interface{}) (map[string]interface{}, error) { } var typMapIfaceIface = reflect.TypeOf(map[interface{}]interface{}{}) +var typByteSlice = reflect.TypeOf([]byte{}) // mapWalker implements interfaces for the reflectwalk package // (github.com/mitchellh/reflectwalk) that can be used to automatically @@ -127,7 +128,7 @@ func (w *mapWalker) Slice(v reflect.Value) error { // If we find a []byte slice, it is an HCL-string converted to []byte. // Convert it back to a Go string and replace the value so that JSON // doesn't base64-encode it. - if v.Type() == reflect.TypeOf([]byte{}) { + if v.Type() == typByteSlice { resultVal := reflect.ValueOf(string(v.Interface().([]byte))) switch w.lastLoc { case reflectwalk.MapKey: @@ -185,6 +186,8 @@ func (w *mapWalker) SliceElem(i int, elem reflect.Value) error { } elem.Set(reflect.ValueOf(target)) + } else if inner := elem.Elem(); inner.Type() == typByteSlice { + elem.Set(reflect.ValueOf(string(inner.Interface().([]byte)))) } return nil diff --git a/lib/map_walker_test.go b/lib/map_walker_test.go index 45c8c0d5e..ad276c684 100644 --- a/lib/map_walker_test.go +++ b/lib/map_walker_test.go @@ -53,6 +53,26 @@ func TestMapWalk(t *testing.T) { "bar": "baz", }, }, + "map with slice": tcase{ + input: map[string]interface{}{ + "foo": []uint8("bar"), + "bar": []interface{}{ + []uint8("one"), + []uint8("two"), + 3, + 4, + }, + }, + expected: map[string]interface{}{ + "foo": "bar", + "bar": []interface{}{ + "one", + "two", + 3, + 4, + }, + }, + }, } for name, tcase := range cases {