From b5dda17f6630b9f454f2b974994affd5421246c5 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Sat, 29 Jan 2022 08:43:40 +0000 Subject: [PATCH] Handle newlines in secrets Signed-off-by: Marcus Noble --- main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1251134..6cd8aaa 100644 --- a/main.go +++ b/main.go @@ -62,11 +62,11 @@ func main() { s.Data = make(map[string][]byte) if item.Username != "" { - s.Data[keys["username"]] = []byte(item.Username) + s.Data[keys["username"]] = []byte(parseNewlines(item.Username)) } if item.Password != "" { - s.Data[keys["password"]] = []byte(item.Password) + s.Data[keys["password"]] = []byte(parseNewlines(item.Password)) } if item.SecretText != "" { @@ -76,11 +76,11 @@ func main() { for _, line := range lines { parts := strings.SplitN(line, "=", 2) if len(parts) == 2 { - s.Data[parts[0]] = []byte(parts[1]) + s.Data[parts[0]] = []byte(parseNewlines(parts[1])) } } } else { - s.Data[keys["secretText"]] = []byte(item.SecretText) + s.Data[keys["secretText"]] = []byte(parseNewlines(item.SecretText)) } } @@ -145,3 +145,7 @@ func parseAnnotations(annotations map[string]string) map[string]string { return keys } + +func parseNewlines(in string) string { + return strings.ReplaceAll(in, "\\n", "\n") +}