Skip to content

Commit 9061d01

Browse files
committed
Handle empty branch in convert
`convert` previously returned a misleading "Incomplete list" error when called on an empty `node`, because the indices branch ran with `minValue == math.MaxInt`. Short-circuit the all-empty case to return an empty `sops.TreeBranch` instead, which is the natural identity for `unflattenTreeBranch(sops.TreeBranch{})`. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent ae2fdad commit 9061d01

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

stores/flatten.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func convert(root *node) (interface{}, error) {
122122
if b2i(hasValue)+b2i(hasSubkey)+b2i(hasIndex) > 1 {
123123
return nil, fmt.Errorf("Type mismatch")
124124
}
125+
if !hasValue && !hasSubkey && !hasIndex {
126+
return sops.TreeBranch{}, nil
127+
}
125128
if hasValue {
126129
return *root.value, nil
127130
}

stores/flatten_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ func TestUnflattenTreeBranch(t *testing.T) {
202202
assert.NotNil(t, err)
203203
assert.Equal(t, "Error while unflattening: Type mismatch", err.Error())
204204
assert.Nil(t, output)
205+
206+
output, err = unflattenTreeBranch(sops.TreeBranch{})
207+
assert.Nil(t, err)
208+
assert.Equal(t, sops.TreeBranch{}, output)
205209
}
206210

207211
func TestFlattenTreeBranch(t *testing.T) {

0 commit comments

Comments
 (0)