diff --git a/pkg/net/url.go b/pkg/net/url.go index 49549ba50..8ec122df4 100644 --- a/pkg/net/url.go +++ b/pkg/net/url.go @@ -21,6 +21,7 @@ import ( "errors" "net/url" "path" + "strings" ) // URL - improved JSON friendly url.URL. @@ -100,6 +101,11 @@ func ParseURL(s string) (u *URL, err error) { uu.Path = path.Clean(uu.Path) } + // path.Clean removes the trailing '/' and converts '//' to '/'. + if strings.HasSuffix(s, "/") && !strings.HasSuffix(uu.Path, "/") { + uu.Path += "/" + } + v := URL(*uu) u = &v return u, nil diff --git a/pkg/net/url_test.go b/pkg/net/url_test.go index 96b8421db..49dcd4339 100644 --- a/pkg/net/url_test.go +++ b/pkg/net/url_test.go @@ -107,8 +107,9 @@ func TestURLUnmarshalJSON(t *testing.T) { {[]byte(`"https://play.min.io:0"`), &URL{Scheme: "https", Host: "play.min.io:0"}, false}, {[]byte(`"https://147.75.201.93:9000/"`), &URL{Scheme: "https", Host: "147.75.201.93:9000", Path: "/"}, false}, {[]byte(`"https://s3.amazonaws.com/?location"`), &URL{Scheme: "https", Host: "s3.amazonaws.com", Path: "/", RawQuery: "location"}, false}, - {[]byte(`"http://myminio:10000/mybucket//myobject/"`), &URL{Scheme: "http", Host: "myminio:10000", Path: "/mybucket/myobject"}, false}, + {[]byte(`"http://myminio:10000/mybucket/myobject//"`), &URL{Scheme: "http", Host: "myminio:10000", Path: "/mybucket/myobject/"}, false}, {[]byte(`"ftp://myftp.server:10000/myuser"`), &URL{Scheme: "ftp", Host: "myftp.server:10000", Path: "/myuser"}, false}, + {[]byte(`"http://webhook.server:10000/mywebhook/"`), &URL{Scheme: "http", Host: "webhook.server:10000", Path: "/mywebhook/"}, false}, {[]byte(`"myserver:1000"`), nil, true}, {[]byte(`"http://:1000/mybucket"`), nil, true}, {[]byte(`"https://147.75.201.93:90000/"`), nil, true}, @@ -142,7 +143,7 @@ func TestParseURL(t *testing.T) { {"https://play.min.io:0", &URL{Scheme: "https", Host: "play.min.io:0"}, false}, {"https://147.75.201.93:9000/", &URL{Scheme: "https", Host: "147.75.201.93:9000", Path: "/"}, false}, {"https://s3.amazonaws.com/?location", &URL{Scheme: "https", Host: "s3.amazonaws.com", Path: "/", RawQuery: "location"}, false}, - {"http://myminio:10000/mybucket//myobject/", &URL{Scheme: "http", Host: "myminio:10000", Path: "/mybucket/myobject"}, false}, + {"http://myminio:10000/mybucket//myobject/", &URL{Scheme: "http", Host: "myminio:10000", Path: "/mybucket/myobject/"}, false}, {"ftp://myftp.server:10000/myuser", &URL{Scheme: "ftp", Host: "myftp.server:10000", Path: "/myuser"}, false}, {"myserver:1000", nil, true}, {"http://:1000/mybucket", nil, true},