On 23 Nov 2009, at 12:41, Maciej Lotkowski wrote: > Hi, > > recently I stumbled upon a problem: > > require 'rubygems' > require 'rack' > require 'rack/mock' > > > app = lambda { |env| > Rack::Request.new(env).GET > } > app.call(Rack::MockRequest.env_for("/kiszka?foo=&foo[option]=kiszka")) remove foo= from the front of your query string. > > The call raises an exception due the invalid query string > > TypeError: expected Hash (got String) for param `_REQUEST' > /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/ > rack-1.0.1/lib/rack/utils.rb:93:in `normalize_params' > /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/ > rack-1.0.1/lib/rack/utils.rb:62:in `parse_nested_query' > /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/ > rack-1.0.1/lib/rack/utils.rb:60:in `each' > /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/ > rack-1.0.1/lib/rack/utils.rb:60:in `parse_nested_query' > /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/ > rack-1.0.1/lib/rack/request.rb:119:in `GET' > > As a workaround I've created a middleware which creates a > Rack::Request > instance, calls GET, catches TypeError if there is any and returns > BadRequest > if an error occured. What is the "right" way to handle this? I think > it would be > better to throw some InvalidQueryString exception from > Rack::Request#GET, > wouldn't it? > > -- > Maciej Lotkowski