releaser: Fix regexp
authorIskander (Alex) Sharipov <i.sharipov@corp.vk.com>
Tue, 12 Oct 2021 09:32:09 +0000 (12:32 +0300)
committerGitHub <noreply@github.com>
Tue, 12 Oct 2021 09:32:09 +0000 (11:32 +0200)
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.

releaser/git.go
releaser/git_test.go

index 4db1c2329c908e3e113379d96f1d90b129399d58..a03a48e99d95108dafd801a6a71e879e7722cf86 100644 (file)
@@ -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"
index 21d261a627f2c44c1de57a70c39143f6b30bc52d..ff77eb8c65c9b219199294c30020467139807130 100644 (file)
@@ -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) {