views:

58

answers:

1

Given the following url: http://example.com?arr[]=hello&arr[]=to&arr[]=you

Am I able to bank on the fact that:

params[:arr] == ['hello', 'to', 'you']

?

I ask because I have some additional data that will be sent with the request that needs to be mapped to each of the values in params[:arr].

+1  A: 

Yes, they are.

Well, maybe a prove from the code where URL parameters are parsed would be handy (I've ommited some code from the example):

#
# file: ../rack-1.2.1/lib/rack/utils.rb
#

def normalize_params(params, name, v = nil)

  # code ommited for simplicity...

  if after == ""
    params[k] = v
  elsif after == "[]"
    params[k] ||= []
    # HERE IT IS!
    params[k] << v
  elsif
  # code ommited for simplicity...
  # ...
end

well, you should take a look yourself but as you can see, the crucial part is where values are simply added to the array - this operation will keep the order.

pawien
Thanks for the code. I'm going to look now at the other crucial part of that method, how the iterator sets k and v.
Brad