MM-21343: Recognize multi-line slash commands without requiring trailing space after trigger word (#13646)

* change how we are parsing the args.command

* change comment

* atttempt to write unit test

* remove quotes

* use unicode.IsSpace

* MM-21343 fix panic

* use table

* test cases

* bad request, add test for missing '/'

* mispelled err

* Update app/command.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* Update app/command.go

Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com>

* use a map

* use subtest and add test case of empty command

* go fmt

* do not use t.fatal

* Update app/command.go

Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>

* fix missing unicode import

Co-authored-by: wiggin77 <wiggin77@warpmail.net>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>
Этот коммит содержится в:
Allen Lai
2020-03-23 10:38:21 -07:00
коммит произвёл GitHub
родитель 37ac6654f6
Коммит ace46443b3
3 изменённых файлов: 61 добавлений и 3 удалений

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

@@ -10,6 +10,7 @@ import (
"net/url"
"strings"
"sync"
"unicode"
goi18n "github.com/mattermost/go-i18n/i18n"
"github.com/mattermost/mattermost-server/v5/mlog"
@@ -159,10 +160,20 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
// @openTracingParams args
func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
parts := strings.Split(args.Command, " ")
trigger := parts[0][1:]
trigger := ""
message := ""
index := strings.IndexFunc(args.Command, unicode.IsSpace)
if index != -1 {
trigger = args.Command[:index]
message = args.Command[index+1:]
} else {
trigger = args.Command
}
trigger = strings.ToLower(trigger)
message := strings.Join(parts[1:], " ")
if !strings.HasPrefix(trigger, "/") {
return nil, model.NewAppError("command", "api.command.execute_command.format.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusBadRequest)
}
trigger = strings.TrimPrefix(trigger, "/")
clientTriggerId, triggerId, appErr := model.GenerateTriggerId(args.UserId, a.AsymmetricSigningKey())
if appErr != nil {