Permalink
Browse files

Skipping empty params inside query what lead to parsing error.

Example of these cookies would be: "foo=bar,;bar=foo" or ",foo=bar;,"
  • Loading branch information...
1 parent 6496241 commit cb05a101cd7eae882cbd0ddd2b3a5c4597b08f28 @josin josin committed Apr 12, 2012
Showing with 3 additions and 0 deletions.
  1. +1 −0 lib/rack/utils.rb
  2. +2 −0 test/spec_utils.rb
View
@@ -67,6 +67,7 @@ def parse_query(qs, d = nil)
params = KeySpaceConstrainedParams.new
(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
+ next if p.empty?
@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) }
next unless k || v
View
@@ -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(";foo=bar,;", ";,").should.equal "foo" => "bar"
+ Rack::Utils.parse_query(",foo=bar;,", ";,").should.equal "foo" => "bar"
end
should "parse nested query strings correctly" do

0 comments on commit cb05a10

Please sign in to comment.