Skip to content

Commit

Permalink
Fix NoMethodError when query hash has nil value
Browse files Browse the repository at this point in the history
The error occurs when using the NON_RAILS_QUERY_STRING_NORMALIZER with a
hash whose key is a symbol and value is nil
  • Loading branch information
sandro committed Apr 20, 2011
1 parent d7e3079 commit 5d56f29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Request #:nodoc:
NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
Array(query).map do |key, value|
if value.nil?
key
key.to_s
elsif value.is_a?(Array)
value.map {|v| "#{key}=#{URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}
else
Expand Down
9 changes: 8 additions & 1 deletion spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
URI.unescape(query_string).should == "foo=bar&foo=baz"
end

context "when representing an array" do
context "when the query is an array" do

it "doesn't include brackets" do
query_string = normalizer[{:page => 1, :foo => %w(bar baz)}]
Expand All @@ -25,6 +25,13 @@
query_string.should == "people=Bob%20Marley&people=Tim%20%26%20Jon"
end
end

context "when the query is a hash" do
it "correctly handles nil values" do
query_string = normalizer[{:page => 1, :per_page => nil}]
query_string.should == "page=1&per_page"
end
end
end

describe "initialization" do
Expand Down

0 comments on commit 5d56f29

Please sign in to comment.