summaryrefslogtreecommitdiffstats
path: root/routers/utils/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/utils/utils.go')
-rw-r--r--routers/utils/utils.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/routers/utils/utils.go b/routers/utils/utils.go
index 64b132ff3e..7c845f8763 100644
--- a/routers/utils/utils.go
+++ b/routers/utils/utils.go
@@ -6,7 +6,10 @@ package utils
import (
"html"
+ "net/url"
"strings"
+
+ "code.gitea.io/gitea/modules/setting"
)
// RemoveUsernameParameterSuffix returns the username parameter without the (fullname) suffix - leaving just the username
@@ -46,3 +49,16 @@ func SanitizeFlashErrorString(x string) string {
return strings.Replace(html.EscapeString(x), "\n", "<br>", -1)
}
+
+// IsExternalURL checks if rawURL points to an external URL like http://example.com
+func IsExternalURL(rawURL string) bool {
+ parsed, err := url.Parse(rawURL)
+ if err != nil {
+ return true
+ }
+ appURL, _ := url.Parse(setting.AppURL)
+ if len(parsed.Host) != 0 && strings.Replace(parsed.Host, "www.", "", 1) != strings.Replace(appURL.Host, "www.", "", 1) {
+ return true
+ }
+ return false
+}