Never remove trailing slash in RelPermalink - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit be964e95a13bce974e4c7af4118979d6fea71112
DIR parent beffe756a91f4c47e8e8fa622b9a52d213a8c821
HTML Author: bep <bjorn.erik.pedersen@gmail.com>
Date: Wed, 27 May 2015 20:41:25 +0200
Never remove trailing slash in RelPermalink
Fixed #1174
Diffstat:
M helpers/path.go | 4 ++++
M helpers/path_test.go | 1 +
M hugolib/page_permalink_test.go | 3 +++
3 files changed, 8 insertions(+), 0 deletions(-)
---
DIR diff --git a/helpers/path.go b/helpers/path.go
@@ -331,6 +331,10 @@ func GetRelativePath(path, base string) (final string, err error) {
if err != nil {
return "", err
}
+
+ if strings.HasSuffix(path, "/") && !strings.HasSuffix(name, "/") {
+ name += "/"
+ }
return name, nil
}
DIR diff --git a/helpers/path_test.go b/helpers/path_test.go
@@ -65,6 +65,7 @@ func TestGetRelativePath(t *testing.T) {
expect interface{}
}{
{filepath.FromSlash("/a/b"), filepath.FromSlash("/a"), filepath.FromSlash("b")},
+ {filepath.FromSlash("/a/b/c/"), filepath.FromSlash("/a"), filepath.FromSlash("b/c/")},
{filepath.FromSlash("/c"), filepath.FromSlash("/a/b"), filepath.FromSlash("../../c")},
{filepath.FromSlash("/c"), "", false},
}
DIR diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go
@@ -26,6 +26,9 @@ func TestPermalink(t *testing.T) {
}{
{"x/y/z/boofar.md", "x/y/z", "", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
{"x/y/z/boofar.md", "x/y/z/", "", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
+ // Issue #1174
+ {"x/y/z/boofar.md", "x/y/z", "http://gopher.com/", "", "", false, true, "http://gopher.com/x/y/z/boofar/", "/x/y/z/boofar/"},
+ {"x/y/z/boofar.md", "x/y/z/", "http://gopher.com/", "", "", true, true, "http://gopher.com/x/y/z/boofar.html", "/x/y/z/boofar.html"},
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", "", false, false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"},
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", "", false, false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"},