Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 83c544a

Browse files
committed
Fix nested hash params in Consumer#request posts
1 parent 5e646b7 commit 83c544a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/oauth/consumer.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,8 @@ def create_http_request(http_method, path, *arguments)
352352
end
353353

354354
if data.is_a?(Hash)
355-
form_data = {}
356-
data.each {|k,v| form_data[k.to_s] = v if !v.nil?}
357-
request.set_form_data(form_data)
355+
request.body = OAuth::Helper.normalize(data)
356+
request.content_type = 'application/x-www-form-urlencoded'
358357
elsif data
359358
if data.respond_to?(:read)
360359
request.body_stream = data

test/test_consumer.rb

+21
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ def test_site_with_path
8989
@consumer.request(:get, '/people', nil, {})
9090
end
9191

92+
def test_post_of_nested_params_maintains_nesting
93+
@consumer=OAuth::Consumer.new(
94+
"key",
95+
"secret",
96+
{
97+
:site=>"http://twitter.com"
98+
})
99+
request = @consumer.create_signed_request(
100+
:post,
101+
'/people',
102+
nil,
103+
{},
104+
{
105+
:key => {
106+
:subkey => 'value'
107+
}
108+
})
109+
assert_equal 'key%5Bsubkey%5D=value', request.body
110+
assert_equal request.content_type, 'application/x-www-form-urlencoded'
111+
end
112+
92113
def test_override_paths
93114
@consumer=OAuth::Consumer.new(
94115
"key",

0 commit comments

Comments
 (0)