From 0962470850ed6802b645d5bd6663db60807c8f5b Mon Sep 17 00:00:00 2001
From: Marek Janda <nyx@nyx.cz>
Date: Mon, 2 Nov 2015 21:28:29 +0100
Subject: [PATCH] Make absURL properly handle baseURL with path component

---
 helpers/url.go      | 12 +++++++++++-
 helpers/url_test.go |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/helpers/url.go b/helpers/url.go
index bebcb866..749b2eea 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -151,7 +151,17 @@ func AbsURL(path string) string {
 	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.
diff --git a/helpers/url_test.go b/helpers/url_test.go
index c484a99a..4774accb 100644
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -53,6 +53,8 @@ func TestAbsURL(t *testing.T) {
 		{"/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 {
-- 
2.30.2