Ticket #3720: build_query_string_hash_patch.diff
| File build_query_string_hash_patch.diff, 1.9 kB (added by gabriel@gironda.org, 4 years ago) |
|---|
-
actionpack/test/controller/url_rewriter_test.rb
old new 19 19 def test_expand_array_build_query_string 20 20 assert_query_equal '?x[]=1&x[]=2', @rewriter.send(:build_query_string, :x => [1, 2]) 21 21 end 22 22 def test_multidimensional_hashes_build_query_string 23 assert_query_equal '?this%5Bis%5D%5Ba%5D=test&this%5Bis_also%5D%5Ba%5D=hash', @rewriter.send(:build_query_string, :this => { 'is' => {'a' => 'test'}, 'is_also' => {'a' => 'hash'} }) 24 end 23 25 def test_escape_spaces_build_query_string_selected_keys 24 26 assert_query_equal '?x=hello+world', @rewriter.send(:build_query_string, {:x => 'hello world', :y => 'goodbye world'}, [:x]) 25 27 end -
actionpack/lib/action_controller/url_rewriter.rb
old new 55 55 query_string = "" 56 56 57 57 only_keys ||= hash.keys 58 59 flatten_query_hash!(hash, only_keys) 58 60 59 61 only_keys.each do |key| 60 62 value = hash[key] … … 70 72 query_string << ("?" + elements.join("&")) unless elements.empty? 71 73 query_string 72 74 end 75 76 # Flattens the query hash so multidimensional hashes in the params hash work properly. 77 def flatten_query_hash!(hash, only_keys) 78 hash.each do |k,v| 79 next unless v.kind_of? Hash 80 v.each do |n,o| 81 hash["#{k}[#{n}]"] = o 82 only_keys << "#{k}[#{n}]" 83 end 84 hash.delete(k) 85 only_keys.delete(k) 86 flatten_query_hash!(hash, only_keys) 87 end 88 end 89 73 90 end 74 91 end