aboutsummaryrefslogtreecommitdiff
path: root/modules/form/form.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-23 11:39:45 -0500
committerUnknwon <u@gogs.io>2017-02-27 22:46:32 -0500
commit429345b9df894465ef98d20358b1757c92b41c80 (patch)
tree56a4499f7e8dd7872696ba919a7f26a6fa870a45 /modules/form/form.go
parenteaab01fa4993d2c9c9141b7526747deb4f21ba2e (diff)
editor: fix cannot create branch with slashes (#3568)
Diffstat (limited to 'modules/form/form.go')
-rw-r--r--modules/form/form.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/form/form.go b/modules/form/form.go
index 1e6fec9e..2efbf4fa 100644
--- a/modules/form/form.go
+++ b/modules/form/form.go
@@ -5,7 +5,9 @@
package form
import (
+ "fmt"
"reflect"
+ "regexp"
"strings"
"github.com/Unknwon/com"
@@ -13,8 +15,24 @@ import (
"gopkg.in/macaron.v1"
)
+const ERR_ALPHA_DASH_DOT_SLASH = "AlphaDashDotSlashError"
+
+var AlphaDashDotSlashPattern = regexp.MustCompile("[^\\d\\w-_\\./]")
+
func init() {
binding.SetNameMapper(com.ToSnakeCase)
+ binding.AddRule(&binding.Rule{
+ IsMatch: func(rule string) bool {
+ return rule == "AlphaDashDotSlash"
+ },
+ IsValid: func(errs binding.Errors, name string, v interface{}) (bool, binding.Errors) {
+ if AlphaDashDotSlashPattern.MatchString(fmt.Sprintf("%v", v)) {
+ errs.Add([]string{name}, ERR_ALPHA_DASH_DOT_SLASH, "AlphaDashDotSlash")
+ return false, errs
+ }
+ return true, errs
+ },
+ })
}
type Form interface {
@@ -113,6 +131,8 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
case binding.ERR_ALPHA_DASH_DOT:
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
+ case ERR_ALPHA_DASH_DOT_SLASH:
+ data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_slash_error")
case binding.ERR_SIZE:
data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field))
case binding.ERR_MIN_SIZE: