From 5da69620cfda5f5ea2b3587581e6ece32269be91 Mon Sep 17 00:00:00 2001 From: Dominic Barnes Date: Wed, 22 Jun 2022 11:34:12 -0700 Subject: [PATCH] trim whitespace from comments before parsing (#2287) --- server/events/comment_parser.go | 6 ++++-- server/events/comment_parser_test.go | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index a4433e863..64fe841dd 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -113,7 +113,9 @@ type CommentParseResult struct { // - atlantis version // - atlantis approve_policies // -func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) CommentParseResult { +func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) CommentParseResult { + comment := strings.TrimSpace(rawComment) + if multiLineRegex.MatchString(comment) { return CommentParseResult{Ignore: true} } @@ -427,7 +429,7 @@ var DidYouMeanAtlantisComment = "Did you mean to use `atlantis` instead of `terr // `atlantis unlock` with flags. var UnlockUsage = "`Usage of unlock:`\n\n ```cmake\n" + - `atlantis unlock + `atlantis unlock Unlocks the entire PR and discards all plans in this PR. Arguments or flags are not supported at the moment. diff --git a/server/events/comment_parser_test.go b/server/events/comment_parser_test.go index 234ff0ecb..c19c404d3 100644 --- a/server/events/comment_parser_test.go +++ b/server/events/comment_parser_test.go @@ -280,6 +280,10 @@ func TestParse_Multiline(t *testing.T) { "atlantis plan\n\n", "atlantis plan\r\n", "atlantis plan\r\n\r\n", + "\natlantis plan", + "\r\natlantis plan", + "\natlantis plan\n", + "\r\natlantis plan\r\n", } for _, comment := range comments { t.Run(comment, func(t *testing.T) { @@ -845,7 +849,7 @@ var ApprovePolicyUsage = `Usage of approve_policies: --verbose Append Atlantis log to comment. ` var UnlockUsage = "`Usage of unlock:`\n\n ```cmake\n" + - `atlantis unlock + `atlantis unlock Unlocks the entire PR and discards all plans in this PR. Arguments or flags are not supported at the moment.