Skip to content

Commit a1e776c

Browse files
committed
Compact comment-skipping in sopsToGoSlice
The previous implementation pre-allocated `result` to `len(slice)` and wrote each non-comment value at its source index. When the input contained comments, the slots at those indices were left as `nil`, producing arrays with embedded nil holes that downstream `mapstructure` decoding would silently accept. Switch to an `append`-based compaction loop, mirroring `flattenDescendArray` in `flatten.go`, so that comments are dropped cleanly and indices on the output remain contiguous. No metadata array carries comments today, so this is a latent fix rather than a behaviour change for any current input. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 8621559 commit a1e776c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

stores/metadata.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ func sopsToGoMap(mapping sops.TreeBranch) (map[string]interface{}, error) {
4747
}
4848

4949
func sopsToGoSlice(slice []interface{}) ([]interface{}, error) {
50-
result := make([]interface{}, len(slice))
51-
for idx, item := range slice {
50+
result := make([]interface{}, 0, len(slice))
51+
for _, item := range slice {
5252
if _, ok := item.(sops.Comment); ok {
5353
continue
5454
}
5555
value, err := sopsToGo(item)
5656
if err != nil {
5757
return nil, err
5858
}
59-
result[idx] = value
59+
result = append(result, value)
6060
}
6161
return result, nil
6262
}

0 commit comments

Comments
 (0)