From 8309e6e710ac7c7d106c85b58e6f3cfc6615c6fa Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Fri, 21 Jun 2019 14:23:12 +0200 Subject: [PATCH] Fix multival (string) requst param parsing (for POST) --- codegen/templates/http_request_inline.tpl | 4 +++- compose/rest/request/notification.go | 8 ++++++-- compose/rest/request/page.go | 4 +++- compose/rest/request/trigger.go | 8 ++++++-- messaging/rest/request/channel.go | 8 ++++++-- messaging/rest/request/message.go | 4 +++- system/rest/request/role.go | 8 ++++++-- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/codegen/templates/http_request_inline.tpl b/codegen/templates/http_request_inline.tpl index d2a81dabd..7e8896d73 100644 --- a/codegen/templates/http_request_inline.tpl +++ b/codegen/templates/http_request_inline.tpl @@ -81,7 +81,9 @@ func (r *{name|expose}{call.name|capitalize}) Fill(req *http.Request) (err error r.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}({/if}chi.URLParam(req, "{param.name}"){if ($param.type !== "string")}){/if} {elseif (substr($param.type, 0, 2) === '[]' || substr($param.type, -3) === "Set") && isset($parsers[$param.type])} {if strtolower($method) === "post"} - r.{param.name|expose} = {$parsers[$param.type]}(req.Form["{param.name}"]) + if val, ok := req.Form["{param.name}"]; ok { + r.{param.name|expose} = {$parsers[$param.type]}(val) + } {elseif strtolower($method) === "get"} if val, ok := urlQuery["{param.name}[]"]; ok { r.{param.name|expose} = {$parsers[$param.type]}(val) diff --git a/compose/rest/request/notification.go b/compose/rest/request/notification.go index 7e29b5c15..3c3f848e7 100644 --- a/compose/rest/request/notification.go +++ b/compose/rest/request/notification.go @@ -84,9 +84,13 @@ func (r *NotificationEmailSend) Fill(req *http.Request) (err error) { post[name] = string(param[0]) } - r.To = parseStrings(req.Form["to"]) + if val, ok := req.Form["to"]; ok { + r.To = parseStrings(val) + } - r.Cc = parseStrings(req.Form["cc"]) + if val, ok := req.Form["cc"]; ok { + r.Cc = parseStrings(val) + } if val, ok := post["replyTo"]; ok { r.ReplyTo = val diff --git a/compose/rest/request/page.go b/compose/rest/request/page.go index db2d5f7cd..f60426878 100644 --- a/compose/rest/request/page.go +++ b/compose/rest/request/page.go @@ -430,7 +430,9 @@ 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"]) + if val, ok := req.Form["pageIDs"]; ok { + r.PageIDs = parseStrings(val) + } return err } diff --git a/compose/rest/request/trigger.go b/compose/rest/request/trigger.go index 936a45baa..b1c2e87b3 100644 --- a/compose/rest/request/trigger.go +++ b/compose/rest/request/trigger.go @@ -166,7 +166,9 @@ func (r *TriggerCreate) Fill(req *http.Request) (err error) { r.Name = val } - r.Actions = parseStrings(req.Form["actions"]) + if val, ok := req.Form["actions"]; ok { + r.Actions = parseStrings(val) + } if val, ok := post["enabled"]; ok { r.Enabled = parseBool(val) @@ -306,7 +308,9 @@ func (r *TriggerUpdate) Fill(req *http.Request) (err error) { r.Name = val } - r.Actions = parseStrings(req.Form["actions"]) + if val, ok := req.Form["actions"]; ok { + r.Actions = parseStrings(val) + } if val, ok := post["enabled"]; ok { r.Enabled = parseBool(val) diff --git a/messaging/rest/request/channel.go b/messaging/rest/request/channel.go index 49915236a..f52e34198 100644 --- a/messaging/rest/request/channel.go +++ b/messaging/rest/request/channel.go @@ -143,7 +143,9 @@ func (r *ChannelCreate) Fill(req *http.Request) (err error) { r.Type = val } - r.Members = parseStrings(req.Form["members"]) + if val, ok := req.Form["members"]; ok { + r.Members = parseStrings(val) + } return err } @@ -642,7 +644,9 @@ func (r *ChannelInvite) Fill(req *http.Request) (err error) { r.ChannelID = parseUInt64(chi.URLParam(req, "channelID")) - r.UserID = parseStrings(req.Form["userID"]) + if val, ok := req.Form["userID"]; ok { + r.UserID = parseStrings(val) + } return err } diff --git a/messaging/rest/request/message.go b/messaging/rest/request/message.go index 445fb6bdd..5a40dd144 100644 --- a/messaging/rest/request/message.go +++ b/messaging/rest/request/message.go @@ -143,7 +143,9 @@ func (r *MessageExecuteCommand) Fill(req *http.Request) (err error) { r.Input = val } - r.Params = parseStrings(req.Form["params"]) + if val, ok := req.Form["params"]; ok { + r.Params = parseStrings(val) + } return err } diff --git a/system/rest/request/role.go b/system/rest/request/role.go index 28b3c2098..a1c4ed88e 100644 --- a/system/rest/request/role.go +++ b/system/rest/request/role.go @@ -133,7 +133,9 @@ func (r *RoleCreate) Fill(req *http.Request) (err error) { r.Name = val } - r.Members = parseStrings(req.Form["members"]) + if val, ok := req.Form["members"]; ok { + r.Members = parseStrings(val) + } return err } @@ -193,7 +195,9 @@ func (r *RoleUpdate) Fill(req *http.Request) (err error) { r.Name = val } - r.Members = parseStrings(req.Form["members"]) + if val, ok := req.Form["members"]; ok { + r.Members = parseStrings(val) + } return err }