Skip to content

Commit

Permalink
releaser: Fix regexp
Browse files Browse the repository at this point in the history
Original regexp used a char class which caused the regexp to only
check 1 symbol instead of a substring like "See" and "Closes".
So it would match `e #x` instead of `See #x` and many other
weird combinations.

Tests were passing as they never checked against an input that
would confuse that regexp.

Found with go-critic static analyzer, `badRegexp` checker.
  • Loading branch information
quasilyte authored Oct 12, 2021
1 parent cd4e67a commit d7331aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion releaser/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/gohugoio/hugo/common/hexec"
)

var issueRe = regexp.MustCompile(`(?i)[Updates?|Closes?|Fix.*|See] #(\d+)`)
var issueRe = regexp.MustCompile(`(?i)(?:Updates?|Closes?|Fix.*|See) #(\d+)`)

const (
notesChanges = "notesChanges"
Expand Down
10 changes: 10 additions & 0 deletions releaser/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ See #456
c.Assert(len(issues), qt.Equals, 4)
c.Assert(issues[0], qt.Equals, 123)
c.Assert(issues[2], qt.Equals, 543)

bodyNoIssues := `
This is a commit message without issue refs.
But it has e #10 to make old regexp confused.
Streets #20.
`

emptyIssuesList := extractIssues(bodyNoIssues)
c.Assert(len(emptyIssuesList), qt.Equals, 0)
}

func TestGitVersionTagBefore(t *testing.T) {
Expand Down

0 comments on commit d7331aa

Please sign in to comment.