File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,12 @@ def normalize(params)
4747 # make sure the array has an element so we don't lose the key
4848 values << nil if values . empty?
4949 # multiple values were provided for a single key
50- values . sort . collect do |v |
51- [ escape ( k ) , escape ( v ) ] * "="
50+ if values [ 0 ] . is_a? ( Hash )
51+ normalize_nested_query ( values , k )
52+ else
53+ values . sort . collect do |v |
54+ [ escape ( k ) , escape ( v ) ] * "="
55+ end
5256 end
5357 elsif values . is_a? ( Hash )
5458 normalize_nested_query ( values , k )
@@ -58,7 +62,7 @@ def normalize(params)
5862 end * "&"
5963 end
6064
61- #Returns a string representation of the Hash like in URL query string
65+ # Returns a string representation of the Hash like in URL query string
6266 # build_nested_query({:level_1 => {:level_2 => ['value_1','value_2']}}, 'prefix'))
6367 # #=> ["prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_1", "prefix%5Blevel_1%5D%5Blevel_2%5D%5B%5D=value_2"]
6468 def normalize_nested_query ( value , prefix = nil )
Original file line number Diff line number Diff line change @@ -82,6 +82,20 @@ def test_normalize
8282 assert_equal ( "oauth_consumer_key=vince_clortho&oauth_nonce=nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1240004133&oauth_token=token_value&oauth_version=1.0&weight%5Bvalue%5D=65" , OAuth ::Helper . normalize ( params ) )
8383 end
8484
85+ def test_normalize_with_nested_array_of_hashes
86+ params = {
87+ "oauth_nonce" => "nonce" ,
88+ "weight" => { :value => "65" } ,
89+ "items" => [ { "a" => 1 } , { "b" => 2 } ] ,
90+ "oauth_signature_method" => "HMAC-SHA1" ,
91+ "oauth_timestamp" => "1240004133" ,
92+ "oauth_consumer_key" => "vince_clortho" ,
93+ "oauth_token" => "token_value" ,
94+ "oauth_version" => "1.0"
95+ }
96+ assert_equal ( "items%5B%5D%5Ba%5D=1&items%5B%5D%5Bb%5D=2&oauth_consumer_key=vince_clortho&oauth_nonce=nonce&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1240004133&oauth_token=token_value&oauth_version=1.0&weight%5Bvalue%5D=65" , OAuth ::Helper . normalize ( params ) )
97+ end
98+
8599 def test_normalize_nested_query
86100 assert_equal ( [ ] , OAuth ::Helper . normalize_nested_query ( { } ) )
87101 assert_equal ( [ "foo=bar" ] , OAuth ::Helper . normalize_nested_query ( { :foo => "bar" } ) )
You can’t perform that action at this time.
0 commit comments