ref: 0962470850ed6802b645d5bd6663db60807c8f5b
parent: 94c3825e5bdda9c57b1e8782caa3c407cfad711e
author: Marek Janda <[email protected]>
date: Mon Nov 2 16:28:29 EST 2015
Make absURL properly handle baseURL with path component
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -151,7 +151,17 @@
if strings.HasPrefix(path, "http") || strings.HasPrefix(path, "//") {
return path
}
- return MakePermalink(viper.GetString("BaseURL"), path).String()
+
+ baseURL := viper.GetString("BaseURL")
+ if strings.HasPrefix(path, "/") {
+ p, err := url.Parse(baseURL)
+ if err != nil {
+ panic(err)
+ }
+ p.Path = ""
+ baseURL = p.String()
+ }
+ return MakePermalink(baseURL, path).String()
}
// RelURL creates a URL relative to the BaseURL root.
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -53,6 +53,8 @@
{"/test/2/foo/", "http://base", "http://base/test/2/foo/"},
{"http://abs", "http://base/", "http://abs"},
{"//schemaless", "http://base/", "//schemaless"},
+ {"test/2/foo/", "http://base/path", "http://base/path/test/2/foo/"},
+ {"/test/2/foo/", "http://base/path", "http://base/test/2/foo/"},
}
for _, test := range tests {