Clean up ref name rules (#6437) (#6439)

This commit is contained in:
mrsdizzie 2019-03-26 17:14:22 -04:00 committed by zeripath
parent 0bf7ed55be
commit 63f6764dce
4 changed files with 132 additions and 4 deletions

View file

@ -19,7 +19,9 @@ const (
var (
// GitRefNamePattern is regular expression with unallowed characters in git reference name
GitRefNamePattern = regexp.MustCompile("[^\\d\\w-_\\./]")
// They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.
// They cannot have question-mark ?, asterisk *, or open bracket [ anywhere
GitRefNamePattern = regexp.MustCompile(`[\000-\037\177 \\~^:?*[]+`)
)
// AddBindingRules adds additional binding rules
@ -44,7 +46,8 @@ func addGitRefNameBindingRule() {
// Additional rules as described at https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
if strings.HasPrefix(str, "/") || strings.HasSuffix(str, "/") ||
strings.HasSuffix(str, ".") || strings.Contains(str, "..") ||
strings.Contains(str, "//") {
strings.Contains(str, "//") || strings.Contains(str, "@{") ||
str == "@" {
errs.Add([]string{name}, ErrGitRefName, "GitRefName")
return false, errs
}