ignore root path, no need strip traling slash

This commit is contained in:
fundon authored and bep committed 2015-01-28 09:43:43 +01:00
1 parent 2d8e15a565
commit ee1045ad42
2 files changed
+7 -4

No files matched your search

+5 -4
View File
@@ -15,11 +15,12 @@ package helpers
import ( import (
"fmt" "fmt"
"github.com/PuerkitoBio/purell"
"github.com/spf13/viper"
"net/url" "net/url"
"path" "path"
"strings" "strings"
"github.com/PuerkitoBio/purell"
"github.com/spf13/viper"
) )
type PathBridge struct { type PathBridge struct {
@@ -120,8 +121,8 @@ func AddContextRoot(baseUrl, relativePath string) string {
newPath := path.Join(url.Path, relativePath) newPath := path.Join(url.Path, relativePath)
// path strips traling slash // path strips traling slash, ignore root path.
if strings.HasSuffix(relativePath, "/") { if newPath != "/" && strings.HasSuffix(relativePath, "/") {
newPath += "/" newPath += "/"
} }
return newPath return newPath
+2
View File
@@ -81,6 +81,8 @@ func TestAddContextRoot(t *testing.T) {
// cannot guess that the context root is already added int the example below // 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/sub/", "/sub/foo", "/sub/sub/foo"},
{"http://example.com/тря", "/трям/", "/тря/трям/"}, {"http://example.com/тря", "/трям/", "/тря/трям/"},
{"http://example.com", "/", "/"},
{"http://example.com/bar", "//", "/bar/"},
} }
for _, test := range tests { for _, test := range tests {