rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: James Tucker <jftucker@gmail.com>
To: rack-devel@googlegroups.com
Subject: Re: Invalid query string handling
Date: Tue, 24 Nov 2009 09:18:25 +0000	[thread overview]
Message-ID: <8253528E-60BA-4C08-AB8D-3FDA8E65E223@gmail.com> (raw)
In-Reply-To: <4f56a124-ba2c-4336-989b-7a8336dc98f4@v37g2000vbb.googlegroups.com>

[-- Attachment #1: Type: text/plain, Size: 1439 bytes --]


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=<empty string> 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


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3679 bytes --]

  reply	other threads:[~2009-11-24  9:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-23 12:41 Invalid query string handling Maciej Lotkowski
2009-11-24  9:18 ` James Tucker [this message]
2009-11-24  9:41   ` Maciej Lotkowski
2009-11-24 10:22     ` James Tucker
2009-11-24  9:25 ` Magnus Holm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8253528E-60BA-4C08-AB8D-3FDA8E65E223@gmail.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).