mirror of https://github.com/gogs/gogs.git
editor: fix cannot create branch with slashes (#3568)
parent
eaab01fa49
commit
429345b9df
|
@ -201,6 +201,7 @@ Content = Content
|
|||
require_error = ` cannot be empty.`
|
||||
alpha_dash_error = ` must be valid alpha or numeric or dash(-_) characters.`
|
||||
alpha_dash_dot_error = ` must be valid alpha or numeric or dash(-_) or dot characters.`
|
||||
alpha_dash_dot_slash_error = ` must be valid alpha or numeric or dash(-_) or dot characters or slashes.`
|
||||
size_error = ` must be size %s.`
|
||||
min_size_error = ` must contain at least %s characters.`
|
||||
max_size_error = ` must contain at most %s characters.`
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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:
|
||||
|
|
|
@ -323,7 +323,7 @@ type EditRepoFile struct {
|
|||
CommitSummary string `binding:"MaxSize(100)`
|
||||
CommitMessage string
|
||||
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||||
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
|
||||
NewBranchName string `binding:"AlphaDashDotSlash;MaxSize(100)"`
|
||||
LastCommit string
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue