mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
Keep trailing slash when baseUrl contains a sub path
Before this commit, .Site.BaseUrl ended up as: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub Now it becomes: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub/ Fixed #931
This commit is contained in:
parent
176ce5deab
commit
9d80ecb4d8
3 changed files with 44 additions and 6 deletions
|
@ -1,9 +1,9 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUrlize(t *testing.T) {
|
||||
|
@ -26,6 +26,34 @@ func TestUrlize(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSanitizeUrl(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"http://foo.bar/", "http://foo.bar/"},
|
||||
{"http://foo.bar/zoo/", "http://foo.bar/zoo"}, // issue #931
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
o1 := SanitizeUrl(test.input)
|
||||
o2 := SanitizeUrlKeepTrailingSlash(test.input)
|
||||
|
||||
expected2 := test.expected
|
||||
|
||||
if strings.HasSuffix(test.input, "/") && !strings.HasSuffix(expected2, "/") {
|
||||
expected2 += "/"
|
||||
}
|
||||
|
||||
if o1 != test.expected {
|
||||
t.Errorf("Expected %#v, got %#v\n", test.expected, o1)
|
||||
}
|
||||
if o2 != expected2 {
|
||||
t.Errorf("Expected %#v, got %#v\n", expected2, o2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakePermalink(t *testing.T) {
|
||||
type test struct {
|
||||
host, link, output string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue