Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle nested params #583

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/httparty/hash_conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.to_params(hash)
def self.normalize_param(key, value)
normalized_keys = normalize_keys(key, value)

normalized_keys.inject('') do |string, (k, v)|
normalized_keys.flatten.each_slice(2).inject('') do |string, (k, v)|
string + "#{k}=#{ERB::Util.url_encode(v.to_s)}&"
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/httparty/hash_conversions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
}
expect(HTTParty::HashConversions.to_params(hash)).to eq("name=bob&address[street]=111%20ruby%20ave.&address[city]=ruby%20central&address[phones][]=111-111-1111&address[phones][]=222-222-2222")
end

context "nested params" do
it 'creates a params string from a hash' do
hash = { marketing_event: { marketed_resources: [ {type:"product", id: 57474842640 } ] } }
expect(HTTParty::HashConversions.to_params(hash)).to eq("marketing_event[marketed_resources][][type]=product&marketing_event[marketed_resources][][id]=57474842640")
end
end
end

describe ".normalize_param" do
Expand Down