Skip to content

Commit

Permalink
fix: Ensure trailing slash in CustomEndpoint is handled gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksgt committed Feb 3, 2021
1 parent b42d2b1 commit bf02e3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions simples3.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func (s3 *S3) SetEndpoint(uri string) *S3 {
if !strings.HasPrefix(uri, "http") {
uri = "https://" + uri
}

// make sure there is no trailing slash
if uri[len(uri)-1] == '/' {
uri = uri[:len(uri)-1]
}
s3.Endpoint = uri
}
return s3
Expand Down
6 changes: 6 additions & 0 deletions simples3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ func TestCustomEndpoint(t *testing.T) {
if s3.getURL("bucket3") != "https://example.com/bucket3" {
t.Errorf("S3.SetEndpoint() got = %v", s3.Endpoint)
}

// try with trailing slash
s3.SetEndpoint("https://example.com/foobar/")
if s3.getURL("bucket4") != "https://example.com/foobar/bucket4" {
t.Errorf("S3.SetEndpoint() got = %v", s3.Endpoint)
}
}

func TestGetURL(t *testing.T) {
Expand Down

0 comments on commit bf02e3b

Please sign in to comment.