Browse Source

editor: fix cannot create branch with slashes (#3568)

pull/4240/head
Unknwon 8 years ago
parent
commit
429345b9df
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 1
      conf/locale/locale_en-US.ini
  2. 1497
      modules/bindata/bindata.go
  3. 20
      modules/form/form.go
  4. 2
      modules/form/repo.go

1
conf/locale/locale_en-US.ini

@ -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.`

1497
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

20
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:

2
modules/form/repo.go

@ -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…
Cancel
Save