summaryrefslogtreecommitdiffstats
path: root/modules/validation/helpers.go
diff options
context:
space:
mode:
authorayb <ayb@3hg.fr>2021-06-26 00:38:27 +0200
committerGitHub <noreply@github.com>2021-06-26 00:38:27 +0200
commit9b33d18899b7e825e4754969ffcc9d7b541d2d28 (patch)
tree0e6a0ea1f7062b18cdaa426b3d2eb42d9ca7ac2a /modules/validation/helpers.go
parentFuzzer finds an NPE due to incorrect URLPrefix (#16249) (diff)
downloadforgejo-9b33d18899b7e825e4754969ffcc9d7b541d2d28.tar.xz
forgejo-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/helpers.go')
-rw-r--r--modules/validation/helpers.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/validation/helpers.go b/modules/validation/helpers.go
index c22e667a2e..343261aac5 100644
--- a/modules/validation/helpers.go
+++ b/modules/validation/helpers.go
@@ -52,6 +52,25 @@ func IsValidURL(uri string) bool {
return true
}
+// IsValidSiteURL checks if URL is valid
+func IsValidSiteURL(uri string) bool {
+ u, err := url.ParseRequestURI(uri)
+ if err != nil {
+ return false
+ }
+
+ if !validPort(portOnly(u.Host)) {
+ return false
+ }
+
+ for _, scheme := range setting.Service.ValidSiteURLSchemes {
+ if scheme == u.Scheme {
+ return true
+ }
+ }
+ return false
+}
+
// IsAPIURL checks if URL is current Gitea instance API URL
func IsAPIURL(uri string) bool {
return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(setting.AppURL+"api"))