Unordered hashes on ruby 1.8 break rack param parsing #54

wr0ngway opened this Issue Feb 1, 2012 · 0 comments


None yet

1 participant

wr0ngway commented Feb 1, 2012

When posting hash params to a server using rack-test, the ordering of elements can cause problems. This isn't a problem in a non-test scenario because the ordering in html determines the ordering of the param string, which gets parsed correctly by rack.
For example, in the following request, a change in the iterated order of the last hash param causes the "fairly" key to get associated with the previous hash when rack parses the generated query string. No idea how one would fix this short of using an OrderedHash in client's test code, but thought I'd mention it in case someone has an idea.

params = {'priorities' => [
    {"pattern" => "foo"},
    {"pattern" => "default"},
    {"pattern" => "bar", "fairly" => "true"}
post "/queuepriority", params 

rack test generates: "priorities[][pattern]=foo&priorities[][pattern]=default&priorities[][pattern]=bar&priorities[][fairly]=true"
rack parses to: {"priorities"=>[{"pattern"=>"foo"}, {"pattern"=>"default"}, {"pattern"=>"bar", "fairly"=>"true"}]}

rack-test generates: "priorities[][pattern]=foo&priorities[][pattern]=default&priorities[][fairly]=true&priorities[][pattern]=bar"
rack parses to: {"priorities"=>[{"pattern"=>"foo"}, {"fairly"=>"true", "pattern"=>"default"}, {"pattern"=>"bar"}]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment