mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
ignore root path, no need strip traling slash
This commit is contained in:
parent
2d8e15a565
commit
ee1045ad42
2 changed files with 7 additions and 4 deletions
|
@ -15,11 +15,12 @@ package helpers
|
|||
|
||||
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 @@ func AddContextRoot(baseUrl, relativePath string) string {
|
|||
|
||||
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
|
||||
|
|
|
@ -81,6 +81,8 @@ func TestAddContextRoot(t *testing.T) {
|
|||
// 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 {
|
||||
|
|
Loading…
Reference in a new issue