mirror of
https://github.com/getsops/sops.git
synced 2026-02-05 12:45:21 +01:00
Add support for decoding JSON arrays of arrays (#642)
Add support for decoding JSON arrays of arrays by handling, during
slice decoding, when the next token is an array opening. This produces
nested []interface{} slices.
Closes #640.
This commit is contained in:
@@ -79,6 +79,12 @@ func (store Store) sliceFromJSONDecoder(dec *json.Decoder) ([]interface{}, error
|
||||
return slice, err
|
||||
}
|
||||
slice = append(slice, item)
|
||||
} else if ok && delim.String() == "[" {
|
||||
item, err := store.sliceFromJSONDecoder(dec)
|
||||
if err != nil {
|
||||
return slice, err
|
||||
}
|
||||
slice = append(slice, item)
|
||||
} else {
|
||||
slice = append(slice, t)
|
||||
}
|
||||
|
||||
@@ -198,6 +198,31 @@ func TestDecodeJSONArrayOfObjects(t *testing.T) {
|
||||
assert.Equal(t, expected, branch)
|
||||
}
|
||||
|
||||
func TestDecodeJSONArrayOfArrays(t *testing.T) {
|
||||
in := `{"foo": [[["foo", {"bar": "foo"}]]]}`
|
||||
expected := sops.TreeBranch{
|
||||
sops.TreeItem{
|
||||
Key: "foo",
|
||||
Value: []interface{}{
|
||||
[]interface{}{
|
||||
[]interface{}{
|
||||
"foo",
|
||||
sops.TreeBranch{
|
||||
sops.TreeItem{
|
||||
Key: "bar",
|
||||
Value: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
branch, err := Store{}.treeBranchFromJSON([]byte(in))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, branch)
|
||||
}
|
||||
|
||||
func TestEncodeSimpleJSON(t *testing.T) {
|
||||
branch := sops.TreeBranch{
|
||||
sops.TreeItem{
|
||||
|
||||
Reference in New Issue
Block a user