Permalink
Browse files

Merge pull request #245 from Billiam/issue/unsorting-request-params

Sorting query parameters undesireable
  • Loading branch information...
jnunemaker committed Jan 4, 2014
2 parents 6cf4fc7 + ac468e0 commit 7c1a19e67db724455a2caf1c6b34d3b3a2d0743c
Showing with 4 additions and 4 deletions.
  1. +2 −2 lib/httparty/request.rb
  2. +2 −2 spec/httparty/request_spec.rb
View
@@ -15,15 +15,15 @@ class Request #:nodoc:
SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]
NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
- Array(query).map do |key, value|
+ Array(query).sort_by { |a| a[0].to_s }.map do |key, value|
if value.nil?
key.to_s
elsif value.is_a?(Array)
value.map {|v| "#{key}=#{URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}
else
HashConversions.to_params(key => value)
end
- end.flatten.sort.join('&')
+ end.flatten.join('&')
end
attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
@@ -21,8 +21,8 @@
end
it "URI encodes array values" do
- query_string = normalizer[{:people => ["Bob Marley", "Tim & Jon"]}]
- query_string.should == "people=Bob%20Marley&people=Tim%20%26%20Jon"
+ query_string = normalizer[{:people => ["Otis Redding", "Bob Marley", "Tim & Jon"], :page => 1, :xyzzy => 3}]
+ query_string.should == "page=1&people=Otis%20Redding&people=Bob%20Marley&people=Tim%20%26%20Jon&xyzzy=3"
end
end

0 comments on commit 7c1a19e

Please sign in to comment.