correct handling for incomplete hash/array parameters #615

merged 2 commits into from Dec 28, 2013


None yet
4 participants

vspy commented Oct 23, 2013

Two problems:

  1. incompete parameters with single bracket caused an exception "Expected Hash, ...", while it is pretty much valid parameter name
  2. rack.request.query_hash should be only set after query is parsed. Otherwise, in case of thrown exception, client will get exception only first time, next time execution goes inside first if block and nil is being returned. This leads to absolutely weird and non-descriptive exception in params method (No method merge for Nil)

vspy commented Nov 1, 2013

Is there something wrong with this pull request?

Why have you added this variable?


vspy replied Nov 26, 2013

There are two ways to prevent @env["rack.request.query_string"] written before actually parsing query. One is to parse it beforehand as I did it, another is to flip @env["rack.request.query_string"]=… and @env["rack.request.query_hash"]=....

I just think that this way it is more implicit that parsing is done before caching query string. But I don't mind to just flip following two lines, if you think it would be better.

As I (maybe very briefly) explained in pull request, this whole situation of writing rack.request.query_string before actually parsing query leads to weird, non-descriptive error messages in case parsing itself ends with throwing some exception. This is especially important when you using rack behind some web-framework. I was using rails when I encountered this bug, and what I have seen - first exception were caught by something inside the rails, but when I tried to access parameters again @env["rack.request.query_string"] == query_string was true, obviously, but @env["rack.request.query_hash"] was nil, so it failed somewhere here, in request.rb trying to merge something into query hash, which was nil.


tenderlove commented Dec 5, 2013

@vspy can you add a test for the second behavior you desire? I see tests for the first behavior, but I'm afraid if we don't have tests for the second behavior, people will just say "why do we have this extra variable?" and there will be a regression.


vspy commented Dec 15, 2013


raggi added a commit that referenced this pull request Dec 28, 2013

Merge pull request #615 from vspy/master
correct handling for incomplete hash/array parameters

@raggi raggi merged commit 23dfded into rack:master Dec 28, 2013

1 check failed

default The Travis CI build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment