Skip to content
This repository

Create an array when multiple instances of the same query parameter are used #519

Closed
wants to merge 1 commit into from

3 participants

Kelley Reynolds Konstantin Haase James Tucker
Kelley Reynolds

This PR is sure to cause controversy, but it seems like broken behavior to disallow the ability for specifying multiple variables to create an array instead of having the last one win. I understand the use of the bracket hash notation and maybe this could be modified to only operate on root variables instead of nested ones, but that seems just as broken/magical to me.

Konstantin Haase
Collaborator

btw, servlets always create an array

Konstantin Haase
Collaborator
rkh commented April 02, 2013

This is a breaking change. Any opinions?

James Tucker
Owner
raggi commented April 21, 2013

Cannot happen before 2.0.

James Tucker raggi closed this April 21, 2013
Andrew Parker zaphod42 referenced this pull request in puppetlabs/puppet September 25, 2013
Closed

(#22652) Parse query strings in rack w/o rack #1938

Matthaus Owens haus referenced this pull request from a commit in haus/puppet September 25, 2013
Andrew Parker (#22652) Parse query strings in rack w/o rack
Rack does not actually support parsing multiple valued query strings
into an array of values (see rack/rack#519).
This is not going to be supported before rack 2.0, but we need this
behavior in order to not have to deal with YAML query parameters.

This changes the rack based query parameter parsing to use CGI.parse
instead of the built in rack semantics (which also has a large number of
other semantics, which we weren't using). As a note, it does not appear
that the behavior of rack's query parameter parsing is documented
anywhere.
8f2967e
ffrank ffrank referenced this pull request from a commit in ffrank/puppet September 25, 2013
Andrew Parker (#22652) Parse query strings in rack w/o rack
Rack does not actually support parsing multiple valued query strings
into an array of values (see rack/rack#519).
This is not going to be supported before rack 2.0, but we need this
behavior in order to not have to deal with YAML query parameters.

This changes the rack based query parameter parsing to use CGI.parse
instead of the built in rack semantics (which also has a large number of
other semantics, which we weren't using). As a note, it does not appear
that the behavior of rack's query parameter parsing is documented
anywhere.
9bd7abc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 14, 2013
Kelley Reynolds Create an array when multiple instances of the same query parameter a…
…re used
0be8bd8
This page is out of date. Refresh to see the latest.
10  lib/rack/utils.rb
@@ -108,7 +108,15 @@ def normalize_params(params, name, v = nil)
108 108
       return if k.empty?
109 109
 
110 110
       if after == ""
111  
-        params[k] = v
  111
+        if cur = params[k]
  112
+          if cur.class == Array
  113
+            params[k] << v
  114
+          else
  115
+            params[k] = [cur, v]
  116
+          end
  117
+        else
  118
+          params[k] = v
  119
+        end
112 120
       elsif after == "[]"
113 121
         params[k] ||= []
114 122
         raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
4  test/spec_utils.rb
@@ -134,7 +134,7 @@ def kcodeu
134 134
       should.equal "foo" => "\"bar\""
135 135
 
136 136
     Rack::Utils.parse_nested_query("foo=bar&foo=quux").
137  
-      should.equal "foo" => "quux"
  137
+      should.equal "foo" => ["bar", "quux"]
138 138
     Rack::Utils.parse_nested_query("foo&foo=").
139 139
       should.equal "foo" => ""
140 140
     Rack::Utils.parse_nested_query("foo=1&bar=2").
@@ -170,7 +170,7 @@ def kcodeu
170 170
     Rack::Utils.parse_nested_query("x[y][z][]=1").
171 171
       should.equal "x" => {"y" => {"z" => ["1"]}}
172 172
     Rack::Utils.parse_nested_query("x[y][z]=1&x[y][z]=2").
173  
-      should.equal "x" => {"y" => {"z" => "2"}}
  173
+      should.equal "x" => {"y" => {"z" => ["1", "2"]}}
174 174
     Rack::Utils.parse_nested_query("x[y][z][]=1&x[y][z][]=2").
175 175
       should.equal "x" => {"y" => {"z" => ["1", "2"]}}
176 176
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.