aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers/url_test.go
diff options
context:
space:
mode:
authorbep <[email protected]>2015-02-28 18:45:02 +0100
committerbep <[email protected]>2015-02-28 18:45:02 +0100
commit9d80ecb4d8efa1a45f649d8b75d7e2c946c09070 (patch)
tree94ec57df8c2234eed8f0dffcdf3cb62afff449d3 /helpers/url_test.go
parent176ce5deab2b6a71789c14a401b8f9ed10399fde (diff)
downloadhugo-9d80ecb4d8efa1a45f649d8b75d7e2c946c09070.tar.gz
hugo-9d80ecb4d8efa1a45f649d8b75d7e2c946c09070.zip
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
Diffstat (limited to 'helpers/url_test.go')
-rw-r--r--helpers/url_test.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/helpers/url_test.go b/helpers/url_test.go
index e27e2bb02..c38750a63 100644
--- a/helpers/url_test.go
+++ b/helpers/url_test.go
@@ -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