Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newline encoding for dotenv store #612

Merged
merged 1 commit into from Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions stores/dotenv/store.go
Expand Up @@ -81,7 +81,7 @@ func (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {
}
branch = append(branch, sops.TreeItem{
Key: string(line[:pos]),
Value: string(line[pos+1:]),
Value: strings.Replace(string(line[pos+1:]), "\\n", "\n", -1),
})
}
}
Expand Down Expand Up @@ -119,7 +119,8 @@ func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) {
if comment, ok := item.Key.(sops.Comment); ok {
line = fmt.Sprintf("#%s\n", comment.Value)
} else {
line = fmt.Sprintf("%s=%s\n", item.Key, item.Value)
value := strings.Replace(item.Value.(string), "\n", "\\n", -1)
line = fmt.Sprintf("%s=%s\n", item.Key, value)
}
buffer.WriteString(line)
}
Expand Down
5 changes: 5 additions & 0 deletions stores/dotenv/store_test.go
Expand Up @@ -13,6 +13,7 @@ VAR1=val1
VAR2=val2
#comment
VAR3_unencrypted=val3
VAR4=val4\nval4
`, "\n"))

var BRANCH = sops.TreeBranch{
Expand All @@ -32,6 +33,10 @@ var BRANCH = sops.TreeBranch{
Key: "VAR3_unencrypted",
Value: "val3",
},
sops.TreeItem{
Key: "VAR4",
Value: "val4\nval4",
},
}

func TestLoadPlainFile(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions stores/stores.go
Expand Up @@ -403,6 +403,10 @@ var ExampleFlatTree = sops.Tree{
Key: "example_key",
Value: "example_value",
},
sops.TreeItem{
Key: "example_multiline",
Value: "foo\nbar\nbaz",
},
},
},
}