ignore root path, no need strip traling slash
authorfundon <cfddream@gmail.com>
Wed, 28 Jan 2015 07:18:09 +0000 (15:18 +0800)
committerbep <bjorn.erik.pedersen@gmail.com>
Wed, 28 Jan 2015 08:43:43 +0000 (09:43 +0100)
helpers/url.go
helpers/url_test.go

index e4db6ceb7b2d348cc48e208caf04f91604186e7d..380ba29c2c2dbbfa69b5956d24aff6b5dbd3e23d 100644 (file)
@@ -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
index 3df1a05c2b8f3a02e6496dfcf17ea5ad57f1b57e..e27e2bb02b4aaa821358d5640e39d5c443a09123 100644 (file)
@@ -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 {