aboutsummaryrefslogtreecommitdiff
path: root/modules/middleware
diff options
context:
space:
mode:
authorFuXiaoHei <fuxiaohei@hexiaz.com>2014-05-01 20:57:11 +0800
committerFuXiaoHei <fuxiaohei@hexiaz.com>2014-05-01 20:57:11 +0800
commitcc1eb5643e3d28b6e23d3642bdf93670c33fa9c5 (patch)
tree7adfbed18647baf9d3e281b7f23c0dcd0828cc7d /modules/middleware
parent52fbb9788aa80adb56c96389f73c878cc0fe8b42 (diff)
parenta2333d95d594a6aa4e77e78c2efe32991d3cf1ef (diff)
Merge branch 'dev' of https://github.com/gogits/gogs into dev
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/binding.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/middleware/binding.go b/modules/middleware/binding.go
index cde9ae9c..bff34ddd 100644
--- a/modules/middleware/binding.go
+++ b/modules/middleware/binding.go
@@ -180,9 +180,10 @@ func Validate(obj interface{}) martini.Handler {
}
var (
- alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
- emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
- urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?`)
+ alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
+ alphaDashDotPattern = regexp.MustCompile("[^\\d\\w-_\\.]")
+ emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
+ urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?`)
)
func validateStruct(errors *base.BindingErrors, obj interface{}) {
@@ -227,6 +228,11 @@ func validateStruct(errors *base.BindingErrors, obj interface{}) {
errors.Fields[field.Name] = base.BindingAlphaDashError
break
}
+ case rule == "AlphaDashDot":
+ if alphaDashDotPattern.MatchString(fmt.Sprintf("%v", fieldValue)) {
+ errors.Fields[field.Name] = base.BindingAlphaDashDotError
+ break
+ }
case strings.HasPrefix(rule, "MinSize("):
min, err := strconv.Atoi(rule[8 : len(rule)-1])
if err != nil {