Skip to content

Commit

Permalink
Skipping empty params inside query what lead to parsing error.
Browse files Browse the repository at this point in the history
Example of these cookies would be: "foo=bar,;bar=foo" or ",foo=bar;,"
  • Loading branch information
josin committed Apr 12, 2012
1 parent 6496241 commit cb05a10
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/utils.rb
Expand Up @@ -67,6 +67,7 @@ def parse_query(qs, d = nil)
params = KeySpaceConstrainedParams.new params = KeySpaceConstrainedParams.new


(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p| (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
next if p.empty?

This comment has been minimized.

Copy link
@sgrunberger

sgrunberger May 29, 2012

I don't yet see the point of this change. If p is an empty string, then on the next line p.split.map will result in an empty array, and we'll skip to the next iteration on the line after that. Is this just for code clarity?

k, v = p.split('=', 2).map { |x| unescape(x) } k, v = p.split('=', 2).map { |x| unescape(x) }
next unless k || v next unless k || v


Expand Down
2 changes: 2 additions & 0 deletions test/spec_utils.rb
Expand Up @@ -118,6 +118,8 @@ def kcodeu
Rack::Utils.parse_query("&key&").should.equal "key" => nil Rack::Utils.parse_query("&key&").should.equal "key" => nil
Rack::Utils.parse_query(";key;", ";,").should.equal "key" => nil Rack::Utils.parse_query(";key;", ";,").should.equal "key" => nil
Rack::Utils.parse_query(",key,", ";,").should.equal "key" => nil Rack::Utils.parse_query(",key,", ";,").should.equal "key" => nil
Rack::Utils.parse_query(";foo=bar,;", ";,").should.equal "foo" => "bar"
Rack::Utils.parse_query(",foo=bar;,", ";,").should.equal "foo" => "bar"
end end


should "parse nested query strings correctly" do should "parse nested query strings correctly" do
Expand Down

0 comments on commit cb05a10

Please sign in to comment.