mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-23 09:43:32 +00:00
parent
16b71bbbb4
commit
e4ee1b89ad
2 changed files with 8 additions and 1 deletions
|
@ -148,7 +148,12 @@ func MakePermalink(host, plink string) *url.URL {
|
||||||
|
|
||||||
// AbsURL creates a absolute URL from the relative path given and the BaseURL set in config.
|
// AbsURL creates a absolute URL from the relative path given and the BaseURL set in config.
|
||||||
func AbsURL(path string) string {
|
func AbsURL(path string) string {
|
||||||
if strings.HasPrefix(path, "http") || strings.HasPrefix(path, "//") {
|
url, err := url.Parse(path)
|
||||||
|
if err != nil {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
if url.IsAbs() || strings.HasPrefix(path, "//") {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,11 @@ func TestAbsURL(t *testing.T) {
|
||||||
{"", "http://base/ace/", "http://base/ace/"},
|
{"", "http://base/ace/", "http://base/ace/"},
|
||||||
{"/test/2/foo/", "http://base", "http://base/test/2/foo/"},
|
{"/test/2/foo/", "http://base", "http://base/test/2/foo/"},
|
||||||
{"http://abs", "http://base/", "http://abs"},
|
{"http://abs", "http://base/", "http://abs"},
|
||||||
|
{"schema://abs", "http://base/", "schema://abs"},
|
||||||
{"//schemaless", "http://base/", "//schemaless"},
|
{"//schemaless", "http://base/", "//schemaless"},
|
||||||
{"test/2/foo/", "http://base/path", "http://base/path/test/2/foo/"},
|
{"test/2/foo/", "http://base/path", "http://base/path/test/2/foo/"},
|
||||||
{"/test/2/foo/", "http://base/path", "http://base/test/2/foo/"},
|
{"/test/2/foo/", "http://base/path", "http://base/test/2/foo/"},
|
||||||
|
{"http//foo", "http://base/path", "http://base/path/http/foo"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in a new issue