|
|
@@ -19,6 +19,8 @@ const ( |
|
|
|
|
|
|
|
// ErrGlobPattern is returned when glob pattern is invalid |
|
|
|
ErrGlobPattern = "GlobPattern" |
|
|
|
|
|
|
|
ErrAlphaDashDotChinese = "AlphaDashDotChineseError" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
@@ -26,6 +28,8 @@ var ( |
|
|
|
// 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 |
|
|
|
GitRefNamePatternInvalid = regexp.MustCompile(`[\000-\037\177 \\~^:?*[]+`) |
|
|
|
|
|
|
|
AlphaDashDotChinese = regexp.MustCompile("^[\u4e00-\u9fa5\\.\\-_A-Za-z0-9]+$") |
|
|
|
) |
|
|
|
|
|
|
|
// CheckGitRefAdditionalRulesValid check name is valid on additional rules |
|
|
@@ -53,6 +57,7 @@ func AddBindingRules() { |
|
|
|
addGitRefNameBindingRule() |
|
|
|
addValidURLBindingRule() |
|
|
|
addGlobPatternRule() |
|
|
|
addAlphaDashDotChineseRule() |
|
|
|
} |
|
|
|
|
|
|
|
func addGitRefNameBindingRule() { |
|
|
@@ -117,6 +122,21 @@ func addGlobPatternRule() { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func addAlphaDashDotChineseRule() { |
|
|
|
binding.AddRule(&binding.Rule{ |
|
|
|
IsMatch: func(rule string) bool { |
|
|
|
return strings.HasPrefix(rule, "AlphaDashDotChinese") |
|
|
|
}, |
|
|
|
IsValid: func(errs binding.Errors, name string, val interface{}) (bool, binding.Errors) { |
|
|
|
if !ValidAlphaDashDotChinese(fmt.Sprintf("%v", val)) { |
|
|
|
errs.Add([]string{name}, ErrAlphaDashDotChinese, "ErrAlphaDashDotChinese") |
|
|
|
return false, errs |
|
|
|
} |
|
|
|
return true, errs |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func portOnly(hostport string) string { |
|
|
|
colon := strings.IndexByte(hostport, ':') |
|
|
|
if colon == -1 { |
|
|
@@ -139,3 +159,7 @@ func validPort(p string) bool { |
|
|
|
} |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
func ValidAlphaDashDotChinese(value string) bool { |
|
|
|
return AlphaDashDotChinese.MatchString(value) |
|
|
|
} |