Skip to content

Commit e1d4302

Browse files
jmooringbep
authored andcommittedJun 12, 2023
helpers: Improve schema detection when creating relative URLs
Fixes #11080
1 parent 5db215d commit e1d4302

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎helpers/url.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ func (p *PathSpec) getBaseURLRoot(path string) string {
152152
func (p *PathSpec) RelURL(in string, addLanguage bool) string {
153153
baseURL := p.getBaseURLRoot(in)
154154
canonifyURLs := p.Cfg.CanonifyURLs()
155-
if (!strings.HasPrefix(in, baseURL) && strings.HasPrefix(in, "http")) || strings.HasPrefix(in, "//") {
155+
156+
url, err := url.Parse(in)
157+
if err != nil {
158+
return in
159+
}
160+
161+
if (!strings.HasPrefix(in, baseURL) && url.IsAbs()) || strings.HasPrefix(in, "//") {
156162
return in
157163
}
158164

‎helpers/url_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func doTestRelURL(t testing.TB, defaultInSubDir, addLanguage, multilingual bool,
177177
{"/foo/bar", "https://example.org/foo/", false, "MULTI/foo/bar"},
178178
{"foo/bar", "https://example.org/foo/", false, "/fooMULTI/foo/bar"},
179179

180+
// Issue 11080
181+
{"mailto:a@b.com", "http://base/", false, "mailto:a@b.com"},
182+
{"ftp://b.com/a.txt", "http://base/", false, "ftp://b.com/a.txt"},
183+
180184
{"/test/foo", "http://base/", false, "MULTI/test/foo"},
181185
{"/" + lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
182186
{lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},

0 commit comments

Comments
 (0)
Please sign in to comment.