mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
helpers: Improve schema detection when creating relative URLs
Fixes #11080
This commit is contained in:
parent
5db215d4d6
commit
e1d43021ca
2 changed files with 11 additions and 1 deletions
|
@ -152,7 +152,13 @@ func (p *PathSpec) getBaseURLRoot(path string) string {
|
||||||
func (p *PathSpec) RelURL(in string, addLanguage bool) string {
|
func (p *PathSpec) RelURL(in string, addLanguage bool) string {
|
||||||
baseURL := p.getBaseURLRoot(in)
|
baseURL := p.getBaseURLRoot(in)
|
||||||
canonifyURLs := p.Cfg.CanonifyURLs()
|
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
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,10 @@ func doTestRelURL(t testing.TB, defaultInSubDir, addLanguage, multilingual bool,
|
||||||
{"/foo/bar", "https://example.org/foo/", false, "MULTI/foo/bar"},
|
{"/foo/bar", "https://example.org/foo/", false, "MULTI/foo/bar"},
|
||||||
{"foo/bar", "https://example.org/foo/", false, "/fooMULTI/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"},
|
{"/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"},
|
||||||
{lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
|
{lang + "/test/foo", "http://base/", false, "/" + lang + "/test/foo"},
|
||||||
|
|
Loading…
Reference in a new issue