Do not add trailing slash to baseURL

Fixes #1105
This commit is contained in:
bep
2015-05-05 16:02:52 +02:00
parent bef3df7481
commit bea9280fb3
3 changed files with 30 additions and 6 deletions

View File

@@ -77,7 +77,7 @@ func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
if err != nil {
panic(err)
}
if !strings.HasPrefix(u.Path, "/") {
if len(u.Path) > 0 && !strings.HasPrefix(u.Path, "/") {
u.Path = "/" + u.Path
}
return u.String()

View File

@@ -31,11 +31,12 @@ func TestSanitizeURL(t *testing.T) {
input string
expected string
}{
{"http://foo.bar/", "http://foo.bar/"},
{"http://foo.bar/", "http://foo.bar"},
{"http://foo.bar", "http://foo.bar"}, // issue #1105
{"http://foo.bar/zoo/", "http://foo.bar/zoo"}, // issue #931
}
for _, test := range tests {
for i, test := range tests {
o1 := SanitizeURL(test.input)
o2 := SanitizeURLKeepTrailingSlash(test.input)
@@ -46,10 +47,10 @@ func TestSanitizeURL(t *testing.T) {
}
if o1 != test.expected {
t.Errorf("Expected %#v, got %#v\n", test.expected, o1)
t.Errorf("[%d] 1: Expected %#v, got %#v\n", i, test.expected, o1)
}
if o2 != expected2 {
t.Errorf("Expected %#v, got %#v\n", expected2, o2)
t.Errorf("[%d] 2: Expected %#v, got %#v\n", i, expected2, o2)
}
}
}