Skip to content

Commit 7f76bf3

Browse files
committed
Force usage of jsonrpc_params
The whole `scrubbed_params` has seems a little fishy to me - it is copying the JSON RPC params up into the main params hash. But it cannot copy all of them because you could then invoke somebody else's chatop command by providing a `chatop` argument to your own command. It is better to separate concerns and just leave the JSON RPC params where they are.
1 parent d483bc3 commit 7f76bf3

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

lib/chatops/controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ def list
2727
end
2828

2929
def process(*args)
30-
scrubbed_params = jsonrpc_params.except(
31-
:user, :mention_slug, :method, :controller, :action, :params, :room_id)
32-
33-
scrubbed_params.each { |k, v| params[k] = v }
34-
3530
if params[:chatop].present?
3631
params[:action] = params[:chatop]
3732
args[0] = params[:action]

spec/lib/chatops/controller_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
chatop :wcid,
1515
/(?:where can i deploy|wcid)(?: (?<app>\S+))?/,
1616
"where can i deploy?" do
17-
return jsonrpc_invalid_params("I need nope, sorry") if params[:app] == "nope"
18-
jsonrpc_success "You can deploy #{params["app"]} just fine."
17+
return jsonrpc_invalid_params("I need nope, sorry") if jsonrpc_params[:app] == "nope"
18+
jsonrpc_success "You can deploy #{jsonrpc_params["app"]} just fine."
1919
end
2020

2121
chatop :foobar,
@@ -35,7 +35,7 @@ def unexcluded_chatop_method
3535
end
3636

3737
def ensure_app_given
38-
return jsonrpc_invalid_params("I need an app, every time") unless params[:app].present?
38+
return jsonrpc_invalid_params("I need an app, every time") unless jsonrpc_params[:app].present?
3939
end
4040
end
4141

0 commit comments

Comments
 (0)