diff options
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/vcs/vcs.go | 8 | ||||
| -rw-r--r-- | pkg/vcs/vcs_test.go | 7 |
2 files changed, 7 insertions, 8 deletions
diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 4359a575e..cffefcde2 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -137,11 +137,7 @@ func CheckBranch(branch string) bool { } func CheckCommitHash(hash string) bool { - if !gitHashRe.MatchString(hash) { - return false - } - ln := len(hash) - return ln == 8 || ln == 10 || ln == 12 || ln == 14 || ln == 16 || ln == 20 || ln == 40 + return gitHashRe.MatchString(hash) } func runSandboxed(dir, command string, args ...string) ([]byte, error) { @@ -157,7 +153,7 @@ var ( // nolint: lll gitRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?/[a-zA-Z0-9-_./]+\.git(/)?$`) gitBranchRe = regexp.MustCompile("^[a-zA-Z0-9-_/.]{2,200}$") - gitHashRe = regexp.MustCompile("^[a-f0-9]+$") + gitHashRe = regexp.MustCompile("^[a-f0-9]{8,40}$") releaseTagRe = regexp.MustCompile(`^v([0-9]+).([0-9]+)(?:\.([0-9]+))?$`) ccRes = []*regexp.Regexp{ regexp.MustCompile(`^Reviewed\-.*: (.*)$`), diff --git a/pkg/vcs/vcs_test.go b/pkg/vcs/vcs_test.go index 0bf9f091d..9e90090a4 100644 --- a/pkg/vcs/vcs_test.go +++ b/pkg/vcs/vcs_test.go @@ -60,15 +60,18 @@ func TestCheckCommitHash(t *testing.T) { testPredicate(t, CheckCommitHash, map[string]bool{ "ff12bea91c22bba93d3ffc3034d813d686bc7eeb": true, // 40 "eae05cb0aaeae05cb0aa": true, // 20 + "449dd6984d0eaabbc": true, // 17 "449dd6984d0eaabb": true, // 16 "a4983672f9ca4c": true, // 14 "449dd6984d0e": true, // 12 + "eae05cb0aab": true, // 11 "eae05cb0aa": true, // 10 "eae05cb0": true, // 8 "": false, "aa": false, - "eae05cb0aab": false, - "xxxxxxxx": false, + "eae05cb": false, + "ff12bea91c22bba93d3ffc3034d813d686bc7eebb": false, + "xxxxxxxx": false, }) } |
