diff options
author | ayb <ayb@3hg.fr> | 2021-06-26 00:38:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 00:38:27 +0200 |
commit | 9b33d18899b7e825e4754969ffcc9d7b541d2d28 (patch) | |
tree | 0e6a0ea1f7062b18cdaa426b3d2eb42d9ca7ac2a /modules/validation/helpers.go | |
parent | Fuzzer finds an NPE due to incorrect URLPrefix (#16249) (diff) | |
download | forgejo-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.go | 19 |
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")) |