From 75cd38950966d3e6713112f3915c8fd314bb28dd Mon Sep 17 00:00:00 2001 From: ikedam Date: Sat, 24 Jul 2021 15:17:50 +0900 Subject: [PATCH 1/2] Add a test to reproduce #907 --- stores/yaml/store_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stores/yaml/store_test.go b/stores/yaml/store_test.go index 05249f4a5..bf7c972f5 100644 --- a/stores/yaml/store_test.go +++ b/stores/yaml/store_test.go @@ -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) From 108b211cfb7e05c4973fbf04ee36a48539308e23 Mon Sep 17 00:00:00 2001 From: ikedam Date: Sat, 24 Jul 2021 15:20:07 +0900 Subject: [PATCH 2/2] Allow empty maps for yaml (#907) --- stores/yaml/store.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stores/yaml/store.go b/stores/yaml/store.go index d9e78b528..da9b946b2 100644 --- a/stores/yaml/store.go +++ b/stores/yaml/store.go @@ -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 {