shithub: hugo

Download patch

ref: ee1045ad42677ca146b2dbed03a5f6481160564c
parent: 2d8e15a5651408fe40b7365334625c487625a1e0
author: fundon <[email protected]>
date: Wed Jan 28 10:18:09 EST 2015

ignore root path, no need strip traling slash

--- a/helpers/url.go
+++ b/helpers/url.go
@@ -15,11 +15,12 @@
 
 import (
 	"fmt"
-	"github.com/PuerkitoBio/purell"
-	"github.com/spf13/viper"
 	"net/url"
 	"path"
 	"strings"
+
+	"github.com/PuerkitoBio/purell"
+	"github.com/spf13/viper"
 )
 
 type PathBridge struct {
@@ -120,8 +121,8 @@
 
 	newPath := path.Join(url.Path, relativePath)
 
-	// path strips traling slash
-	if strings.HasSuffix(relativePath, "/") {
+	// path strips traling slash, ignore root path.
+	if newPath != "/" && strings.HasSuffix(relativePath, "/") {
 		newPath += "/"
 	}
 	return newPath
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -81,6 +81,8 @@
 		// cannot guess that the context root is already added int the example below
 		{"http://example.com/sub/", "/sub/foo", "/sub/sub/foo"},
 		{"http://example.com/тря", "/трям/", "/тря/трям/"},
+		{"http://example.com", "/", "/"},
+		{"http://example.com/bar", "//", "/bar/"},
 	}
 
 	for _, test := range tests {