diff options
author | ayb <ayb@3hg.fr> | 2021-06-26 00:38:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-25 18:38:27 -0400 |
commit | 9b33d18899b7e825e4754969ffcc9d7b541d2d28 (patch) | |
tree | 0e6a0ea1f7062b18cdaa426b3d2eb42d9ca7ac2a /modules/validation/binding.go | |
parent | 1a1ce9b7216ab80e94987270da8fc2def57237c0 (diff) | |
download | gitea-9b33d18899b7e825e4754969ffcc9d7b541d2d28.tar.gz gitea-9b33d18899b7e825e4754969ffcc9d7b541d2d28.zip |
Added support for gopher URLs. (#14749)
* Added support for gopher URLs.
* Add setting and make this user settable instead
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/validation/binding.go')
-rw-r--r-- | modules/validation/binding.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/validation/binding.go b/modules/validation/binding.go index 4cef48daf3..5d5c64611f 100644 --- a/modules/validation/binding.go +++ b/modules/validation/binding.go @@ -55,6 +55,7 @@ func CheckGitRefAdditionalRulesValid(name string) bool { func AddBindingRules() { addGitRefNameBindingRule() addValidURLBindingRule() + addValidSiteURLBindingRule() addGlobPatternRule() addRegexPatternRule() addGlobOrRegexPatternRule() @@ -102,6 +103,24 @@ func addValidURLBindingRule() { }) } +func addValidSiteURLBindingRule() { + // URL validation rule + binding.AddRule(&binding.Rule{ + IsMatch: func(rule string) bool { + return strings.HasPrefix(rule, "ValidSiteUrl") + }, + IsValid: func(errs binding.Errors, name string, val interface{}) (bool, binding.Errors) { + str := fmt.Sprintf("%v", val) + if len(str) != 0 && !IsValidSiteURL(str) { + errs.Add([]string{name}, binding.ERR_URL, "Url") + return false, errs + } + + return true, errs + }, + }) +} + func addGlobPatternRule() { binding.AddRule(&binding.Rule{ IsMatch: func(rule string) bool { |