mirror of
https://github.com/gogs/gogs.git
synced 2025-05-31 11:42:13 +00:00
editor: fix cannot create branch with slashes (#3568)
This commit is contained in:
parent
eaab01fa49
commit
429345b9df
@ -201,6 +201,7 @@ Content = Content
|
|||||||
require_error = ` cannot be empty.`
|
require_error = ` cannot be empty.`
|
||||||
alpha_dash_error = ` must be valid alpha or numeric or dash(-_) characters.`
|
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_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.`
|
size_error = ` must be size %s.`
|
||||||
min_size_error = ` must contain at least %s characters.`
|
min_size_error = ` must contain at least %s characters.`
|
||||||
max_size_error = ` must contain at most %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
|
package form
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
@ -13,8 +15,24 @@ import (
|
|||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ERR_ALPHA_DASH_DOT_SLASH = "AlphaDashDotSlashError"
|
||||||
|
|
||||||
|
var AlphaDashDotSlashPattern = regexp.MustCompile("[^\\d\\w-_\\./]")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
binding.SetNameMapper(com.ToSnakeCase)
|
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 {
|
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")
|
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_error")
|
||||||
case binding.ERR_ALPHA_DASH_DOT:
|
case binding.ERR_ALPHA_DASH_DOT:
|
||||||
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
|
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:
|
case binding.ERR_SIZE:
|
||||||
data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field))
|
data["ErrorMsg"] = trName + l.Tr("form.size_error", getSize(field))
|
||||||
case binding.ERR_MIN_SIZE:
|
case binding.ERR_MIN_SIZE:
|
||||||
|
@ -323,7 +323,7 @@ type EditRepoFile struct {
|
|||||||
CommitSummary string `binding:"MaxSize(100)`
|
CommitSummary string `binding:"MaxSize(100)`
|
||||||
CommitMessage string
|
CommitMessage string
|
||||||
CommitChoice string `binding:"Required;MaxSize(50)"`
|
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||||||
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
|
NewBranchName string `binding:"AlphaDashDotSlash;MaxSize(100)"`
|
||||||
LastCommit string
|
LastCommit string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user