Trimmed trailing slash in URL provided to create Client API (#15513)

Этот коммит содержится в:
Jared Shields
2020-09-24 06:06:36 -04:00
коммит произвёл GitHub
родитель ee76ad435b
Коммит e726b04268
2 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@@ -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{}, "", ""}
}

Просмотреть файл

@@ -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{