Repository: gohugoio/hugo (language: go)

Issue:
relURL and relLangURL ignore schemas other than http/https
Example:

```
{{ relURL "ftp://exampl.org/file.txt" }} --> /ftp:/example.com/file.txt
```

Reference: <https://discourse.gohugo.io/t/44756>


Discussion / hints:

Fix patch:
diff --git a/helpers/url.go b/helpers/url.go
index a4c20c6ad8d..bd336545b08 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -152,7 +152,13 @@ func (p *PathSpec) getBaseURLRoot(path string) string {
 func (p *PathSpec) RelURL(in string, addLanguage bool) string {
 	baseURL := p.getBaseURLRoot(in)
 	canonifyURLs := p.Cfg.CanonifyURLs()
-	if (!strings.HasPrefix(in, baseURL) && strings.HasPrefix(in, "http")) || strings.HasPrefix(in, "//") {
+
+	url, err := url.Parse(in)
+	if err != nil {
+		return in
+	}
+
+	if (!strings.HasPrefix(in, baseURL) && url.IsAbs()) || strings.HasPrefix(in, "//") {
 		return in
 	}
 


Test patch:
diff --git a/helpers/url_test.go b/helpers/url_test.go
index 787cdd6e851..b3272d9425d 100644
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -177,6 +177,10 @@ func doTestRelURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool,
 		{"/foo/bar", "https://example.org/foo/", false, "MULTI/foo/bar"},
 		{"foo/bar", "https://example.org/foo/", false, "/fooMULTI/foo/bar"},
 
+		// Issue 11080
+		{"mailto:a@b.com", "http://base/", false, "mailto:a@b.com"},
+		{"ftp://b.com/a.txt", "http://base/", false, "ftp://b.com/a.txt"},
+
 		{"/test/foo", "http://base/", false, "MULTI/test/foo"},
 		{"/" + lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
 		{lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},