Skip to content

Commit

Permalink
🐛 (flags): Fix error when value starts or ends with a newline
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 22, 2023
1 parent 049e664 commit 6552d3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/util/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ func FixStringToStringNewlines(s []string) []string {
replaceNext = false
if strings.ContainsRune(arg, '=') {
if strings.ContainsRune(arg, '\n') {
s[i] = strings.ReplaceAll(arg, "\n", ",")
arg = strings.ReplaceAll(arg, "\n", ",")
arg = strings.Trim(arg, ",")
arg = strings.Replace(arg, "=,", "=", 1)
s[i] = arg
}
} else {
replaceNext = true
Expand Down
1 change: 1 addition & 0 deletions internal/util/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestFixStringToStringNewlines(t *testing.T) {
{"newline with space", args{[]string{"yampl", "--value", "a=a\nb=b"}}, []string{"yampl", "--value", "a=a,b=b"}},
{"newline in file", args{[]string{"yampl", "test\nfile.yaml"}}, []string{"yampl", "test\nfile.yaml"}},
{"newline after end of options", args{[]string{"yampl", "-v=a=a", "---", "-v\nfile.yaml"}}, []string{"yampl", "-v=a=a", "---", "-v\nfile.yaml"}},
{"trim newline", args{[]string{"yampl", "-v=\na=a\n"}}, []string{"yampl", "-v=a=a"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 6552d3d

Please sign in to comment.