Skip to content

Commit

Permalink
🐛 (flags): Fix error when value has consecutive newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 22, 2023
1 parent 6552d3d commit 21eb039
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/util/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"github.com/clevyr/yampl/cmd"
"regexp"
"strings"
)

Expand All @@ -15,7 +16,7 @@ func FixStringToStringNewlines(s []string) []string {
replaceNext = false
if strings.ContainsRune(arg, '=') {
if strings.ContainsRune(arg, '\n') {
arg = strings.ReplaceAll(arg, "\n", ",")
arg = regexp.MustCompile("\n+").ReplaceAllString(arg, ",")
arg = strings.Trim(arg, ",")
arg = strings.Replace(arg, "=,", "=", 1)
s[i] = arg
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 @@ -21,6 +21,7 @@ func TestFixStringToStringNewlines(t *testing.T) {
{"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"}},
{"collapse newlines", args{[]string{"yampl", "-v=a=a\n\nb=b"}}, []string{"yampl", "-v=a=a,b=b"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 21eb039

Please sign in to comment.