From ee1045ad42677ca146b2dbed03a5f6481160564c Mon Sep 17 00:00:00 2001 From: fundon Date: Wed, 28 Jan 2015 15:18:09 +0800 Subject: [PATCH] ignore root path, no need strip traling slash --- helpers/url.go | 9 +++++---- helpers/url_test.go | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/helpers/url.go b/helpers/url.go index e4db6ceb7..380ba29c2 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -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 diff --git a/helpers/url_test.go b/helpers/url_test.go index 3df1a05c2..e27e2bb02 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -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 {