From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.142.191.1 with SMTP id o1cs28958wff; Tue, 24 Nov 2009 01:26:13 -0800 (PST) Received: from mr.google.com ([10.90.10.19]) by 10.90.10.19 with SMTP id 19mr3108091agj.9.1259054773379 (num_hops = 1); Tue, 24 Nov 2009 01:26:13 -0800 (PST) Received: by 10.90.10.19 with SMTP id 19mr276791agj.9.1259054771984; Tue, 24 Nov 2009 01:26:11 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.204.16.73 with SMTP id n9ls147658bka.3.p; Tue, 24 Nov 2009 01:26:10 -0800 (PST) Received: by 10.204.23.6 with SMTP id p6mr200527bkb.34.1259054770244; Tue, 24 Nov 2009 01:26:10 -0800 (PST) Received: by 10.204.23.6 with SMTP id p6mr200526bkb.34.1259054770224; Tue, 24 Nov 2009 01:26:10 -0800 (PST) Return-Path: Received: from mail-bw0-f213.google.com (mail-bw0-f213.google.com [209.85.218.213]) by gmr-mx.google.com with ESMTP id 18si292450bwz.9.2009.11.24.01.26.09; Tue, 24 Nov 2009 01:26:09 -0800 (PST) Received-SPF: pass (google.com: domain of judofyr@gmail.com designates 209.85.218.213 as permitted sender) client-ip=209.85.218.213; Received: by mail-bw0-f213.google.com with SMTP id 5so6204077bwz.3 for ; Tue, 24 Nov 2009 01:26:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.153.220 with SMTP id l28mr5891116bkw.86.1259054769124; Tue, 24 Nov 2009 01:26:09 -0800 (PST) In-Reply-To: <4f56a124-ba2c-4336-989b-7a8336dc98f4@v37g2000vbb.googlegroups.com> References: <4f56a124-ba2c-4336-989b-7a8336dc98f4@v37g2000vbb.googlegroups.com> From: Magnus Holm Date: Tue, 24 Nov 2009 10:25:49 +0100 Message-ID: <391a49da0911240125h59b6d97ar3422bff380e64e42@mail.gmail.com> Subject: Re: Invalid query string handling To: rack-devel@googlegroups.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of judofyr@gmail.com designates 209.85.218.213 as permitted sender) smtp.mail=judofyr@gmail.com; dkim=pass (test mode) header.i=@gmail.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rack-devel/t/72a3361c049286ac X-Message-Url: http://groups.google.com/group/rack-devel/msg/9368c572098ce929 List-Unsubscribe: , List-Subscribe: , Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Maybe we should have a Rack::BadRequest, which can be raised when needed? //Magnus Holm On Mon, Nov 23, 2009 at 13:41, Maciej Lotkowski wrote: > Hi, > > recently I stumbled upon a problem: > > require 'rubygems' > require 'rack' > require 'rack/mock' > > > app =3D lambda { |env| > =C2=A0Rack::Request.new(env).GET > } > app.call(Rack::MockRequest.env_for("/kiszka?foo=3D&foo[option]=3Dkiszka")= ) > > The call raises an exception due the invalid query string > > TypeError: expected Hash (got String) for param `_REQUEST' > =C2=A0 =C2=A0/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' > =C2=A0 =C2=A0/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' > =C2=A0 =C2=A0/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' > =C2=A0 =C2=A0/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' > =C2=A0 =C2=A0/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 >