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

🐛 Trim extra newlines in messages #111

Merged
merged 1 commit into from
Jan 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/conversion/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,8 @@ func substituteWhere(where map[string]string, pattern string) string {

func trimMessage(s string) string {
re := regexp.MustCompile(`( ){2,}`)
return re.ReplaceAllString(s, " ")
trimmed := strings.TrimSpace(s)
return re.ReplaceAllString(trimmed, " ")
}

func flattenWhere(wheres []windup.Where) map[string]string {
Expand Down
26 changes: 26 additions & 0 deletions pkg/conversion/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,29 @@ func Test_convertMessageString(t *testing.T) {
})
}
}

func Test_trimMessage(t *testing.T) {
tests := []struct {
name string
msg string
want string
}{
{
name: "message with trailing and ending newlines",
msg: "\n\ntest message\n\n",
want: "test message",
},
{
name: "message with newlines in the middle",
msg: "\n\ntest \n message\n\n",
want: "test \n message",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := trimMessage(tt.msg); got != tt.want {
t.Errorf("convertMessageString() = %v, want %v", got, tt.want)
}
})
}
}
Loading