aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-01-10 14:33:03 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-01-10 14:35:45 +0100
commitda53282acc8fcdec3666ce8e9f4cea5e4be9502e (patch)
tree1a3aceabe5a62608ce3167bf8b3bc8e1e67ff762 /pkg/vcs
parent7835524884fcb42e05bb3966cab291fa868178d4 (diff)
pkg/vcs: relax check on git hash length
We've seen 15 and 17 char hashes already. And 14 wasn't initially in the list, but somebody used it. Relax the check to 8..40 chars.
Diffstat (limited to 'pkg/vcs')
-rw-r--r--pkg/vcs/vcs.go8
-rw-r--r--pkg/vcs/vcs_test.go7
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,
})
}