diff --git a/model/client4.go b/model/client4.go index 03378b4ae9..832f12d9af 100644 --- a/model/client4.go +++ b/model/client4.go @@ -116,6 +116,7 @@ func (c *Client4) Must(result interface{}, resp *Response) interface{} { } func NewAPIv4Client(url string) *Client4 { + url = strings.TrimRight(url, "/") return &Client4{url, url + API_URL_SUFFIX, &http.Client{}, "", "", map[string]string{}, "", ""} } diff --git a/model/client4_test.go b/model/client4_test.go index 3734bf4117..1296c0ddae 100644 --- a/model/client4_test.go +++ b/model/client4_test.go @@ -12,6 +12,19 @@ import ( "github.com/stretchr/testify/assert" ) +// https://github.com/mattermost/mattermost-plugin-starter-template/issues/115 +func TestClient4TrimTrailingSlash(t *testing.T) { + slashes := []int{0, 1, 5} + baseUrl := "https://foo.com:1234" + + for _, s := range slashes { + testUrl := baseUrl + strings.Repeat("/", s) + client := NewAPIv4Client(testUrl) + assert.Equal(t, baseUrl, client.Url) + assert.Equal(t, baseUrl+API_URL_SUFFIX, client.ApiUrl) + } +} + // https://github.com/mattermost/mattermost-server/v5/issues/8205 func TestClient4CreatePost(t *testing.T) { post := &Post{