From b7f78cdf91c49fad3e76ac4b1b08dbf77a32b0b0 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 20 Jun 2019 11:03:46 +0200 Subject: [PATCH] Fix multival (string) request param parsing --- codegen/codegen.php | 1 + compose/rest/request/notification.go | 4 ++++ compose/rest/request/page.go | 2 ++ compose/rest/request/trigger.go | 6 ++++++ compose/rest/request/util.go | 4 ++++ messaging/rest/request/channel.go | 4 ++++ messaging/rest/request/message.go | 2 ++ messaging/rest/request/search.go | 31 ++++++++++++++++++++++++++++ messaging/rest/request/util.go | 4 ++++ system/rest/request/role.go | 4 ++++ system/rest/request/util.go | 4 ++++ 11 files changed, 66 insertions(+) diff --git a/codegen/codegen.php b/codegen/codegen.php index e0e7c3acb..1fbf216e7 100755 --- a/codegen/codegen.php +++ b/codegen/codegen.php @@ -98,6 +98,7 @@ usort($apis, function($a, $b) { $parsers = array( "uint64" => "parseUInt64", "[]uint64" => "parseUInt64A", + "[]string" => "parseStrings", "int" => "parseInt", "uint" => "parseUint", "bool" => "parseBool", diff --git a/compose/rest/request/notification.go b/compose/rest/request/notification.go index c529a32a8..7e29b5c15 100644 --- a/compose/rest/request/notification.go +++ b/compose/rest/request/notification.go @@ -84,6 +84,10 @@ func (r *NotificationEmailSend) Fill(req *http.Request) (err error) { post[name] = string(param[0]) } + r.To = parseStrings(req.Form["to"]) + + r.Cc = parseStrings(req.Form["cc"]) + if val, ok := post["replyTo"]; ok { r.ReplyTo = val } diff --git a/compose/rest/request/page.go b/compose/rest/request/page.go index 09b0e9ccb..db2d5f7cd 100644 --- a/compose/rest/request/page.go +++ b/compose/rest/request/page.go @@ -430,6 +430,8 @@ func (r *PageReorder) Fill(req *http.Request) (err error) { r.SelfID = parseUInt64(chi.URLParam(req, "selfID")) r.NamespaceID = parseUInt64(chi.URLParam(req, "namespaceID")) + r.PageIDs = parseStrings(req.Form["pageIDs"]) + return err } diff --git a/compose/rest/request/trigger.go b/compose/rest/request/trigger.go index 9e213823c..936a45baa 100644 --- a/compose/rest/request/trigger.go +++ b/compose/rest/request/trigger.go @@ -165,6 +165,9 @@ func (r *TriggerCreate) Fill(req *http.Request) (err error) { if val, ok := post["name"]; ok { r.Name = val } + + r.Actions = parseStrings(req.Form["actions"]) + if val, ok := post["enabled"]; ok { r.Enabled = parseBool(val) } @@ -302,6 +305,9 @@ func (r *TriggerUpdate) Fill(req *http.Request) (err error) { if val, ok := post["name"]; ok { r.Name = val } + + r.Actions = parseStrings(req.Form["actions"]) + if val, ok := post["enabled"]; ok { r.Enabled = parseBool(val) } diff --git a/compose/rest/request/util.go b/compose/rest/request/util.go index 40faa24fb..9274431f8 100644 --- a/compose/rest/request/util.go +++ b/compose/rest/request/util.go @@ -79,6 +79,10 @@ func parseUInt64A(values []string) []uint64 { return result } +func parseStrings(values []string) []string { + return values +} + // parseUInt64 parses a string to uint64 func parseBool(s string) bool { return truthy.MatchString(strings.ToLower(s)) diff --git a/messaging/rest/request/channel.go b/messaging/rest/request/channel.go index dd80ce4dd..49915236a 100644 --- a/messaging/rest/request/channel.go +++ b/messaging/rest/request/channel.go @@ -143,6 +143,8 @@ func (r *ChannelCreate) Fill(req *http.Request) (err error) { r.Type = val } + r.Members = parseStrings(req.Form["members"]) + return err } @@ -640,6 +642,8 @@ func (r *ChannelInvite) Fill(req *http.Request) (err error) { r.ChannelID = parseUInt64(chi.URLParam(req, "channelID")) + r.UserID = parseStrings(req.Form["userID"]) + return err } diff --git a/messaging/rest/request/message.go b/messaging/rest/request/message.go index 2e80029e7..445fb6bdd 100644 --- a/messaging/rest/request/message.go +++ b/messaging/rest/request/message.go @@ -143,6 +143,8 @@ func (r *MessageExecuteCommand) Fill(req *http.Request) (err error) { r.Input = val } + r.Params = parseStrings(req.Form["params"]) + return err } diff --git a/messaging/rest/request/search.go b/messaging/rest/request/search.go index 780eddc72..2fdf006c6 100644 --- a/messaging/rest/request/search.go +++ b/messaging/rest/request/search.go @@ -96,6 +96,12 @@ func (r *SearchMessages) Fill(req *http.Request) (err error) { post[name] = string(param[0]) } + if val, ok := urlQuery["channelID[]"]; ok { + r.ChannelID = parseStrings(val) + } else if val, ok = urlQuery["channelID"]; ok { + r.ChannelID = parseStrings(val) + } + if val, ok := get["afterMessageID"]; ok { r.AfterMessageID = parseUInt64(val) } @@ -108,6 +114,25 @@ func (r *SearchMessages) Fill(req *http.Request) (err error) { if val, ok := get["toMessageID"]; ok { r.ToMessageID = parseUInt64(val) } + + if val, ok := urlQuery["threadID[]"]; ok { + r.ThreadID = parseStrings(val) + } else if val, ok = urlQuery["threadID"]; ok { + r.ThreadID = parseStrings(val) + } + + if val, ok := urlQuery["userID[]"]; ok { + r.UserID = parseStrings(val) + } else if val, ok = urlQuery["userID"]; ok { + r.UserID = parseStrings(val) + } + + if val, ok := urlQuery["type[]"]; ok { + r.Type = parseStrings(val) + } else if val, ok = urlQuery["type"]; ok { + r.Type = parseStrings(val) + } + if val, ok := get["pinnedOnly"]; ok { r.PinnedOnly = parseBool(val) } @@ -174,6 +199,12 @@ func (r *SearchThreads) Fill(req *http.Request) (err error) { post[name] = string(param[0]) } + if val, ok := urlQuery["channelID[]"]; ok { + r.ChannelID = parseStrings(val) + } else if val, ok = urlQuery["channelID"]; ok { + r.ChannelID = parseStrings(val) + } + if val, ok := get["limit"]; ok { r.Limit = parseUint(val) } diff --git a/messaging/rest/request/util.go b/messaging/rest/request/util.go index 2059f1ff8..83b2228a0 100644 --- a/messaging/rest/request/util.go +++ b/messaging/rest/request/util.go @@ -65,6 +65,10 @@ func parseUInt64A(values []string) []uint64 { return result } +func parseStrings(values []string) []string { + return values +} + // parseUInt64 parses a string to uint64 func parseBool(s string) bool { return truthy.MatchString(strings.ToLower(s)) diff --git a/system/rest/request/role.go b/system/rest/request/role.go index b1e19e0df..28b3c2098 100644 --- a/system/rest/request/role.go +++ b/system/rest/request/role.go @@ -133,6 +133,8 @@ func (r *RoleCreate) Fill(req *http.Request) (err error) { r.Name = val } + r.Members = parseStrings(req.Form["members"]) + return err } @@ -191,6 +193,8 @@ func (r *RoleUpdate) Fill(req *http.Request) (err error) { r.Name = val } + r.Members = parseStrings(req.Form["members"]) + return err } diff --git a/system/rest/request/util.go b/system/rest/request/util.go index 7f96b3e5d..d4c308d49 100644 --- a/system/rest/request/util.go +++ b/system/rest/request/util.go @@ -56,6 +56,10 @@ func parseUInt64A(values []string) []uint64 { return result } +func parseStrings(values []string) []string { + return values +} + // parseUInt64 parses a string to uint64 func parseBool(s string) bool { return truthy.MatchString(strings.ToLower(s))