Skip to content

Commit

Permalink
Merge pull request #908 from ikedam/feature/907_FixEmptyYaml
Browse files Browse the repository at this point in the history
Allow empty maps for yaml (#907)
  • Loading branch information
ajvb authored Mar 22, 2022
2 parents 66090e7 + 63fa89c commit e2c0479
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 1 addition & 5 deletions stores/yaml/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,7 @@ func (store *Store) EmitPlainFile(branches sops.TreeBranches) ([]byte, error) {
mapping.Kind = yaml.MappingNode
// Marshal branch to global mapping node
store.appendTreeBranch(branch, &mapping)
if len(mapping.Content) == 0 {
doc.HeadComment = mapping.HeadComment
} else {
doc.Content = append(doc.Content, &mapping)
}
doc.Content = append(doc.Content, &mapping)
// Encode YAML
err := e.Encode(&doc)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions stores/yaml/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ func TestEmpty2(t *testing.T) {
}
*/

func TestEmpty3(t *testing.T) {
branches, err := (&Store{}).LoadPlainFile([]byte("{}\n"))
assert.Nil(t, err)
assert.Equal(t, len(branches), 1)
bytes, err := (&Store{}).EmitPlainFile(branches)
assert.Nil(t, err)
assert.Equal(t, "{}\n", string(bytes))
}

func TestComment6(t *testing.T) {
branches, err := (&Store{}).LoadPlainFile(COMMENT_6)
assert.Nil(t, err)
Expand Down

0 comments on commit e2c0479

Please sign in to comment.