From 4f28a16dd7fac9812b6d689f0df92886a02fdc1a Mon Sep 17 00:00:00 2001 From: akiicat Date: Mon, 8 May 2017 15:34:29 +0800 Subject: [PATCH] Fix HTTP::Params.parse query string with two '=' --- spec/std/http/params_spec.cr | 1 + src/http/params.cr | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/std/http/params_spec.cr b/spec/std/http/params_spec.cr index c3db2b879d3f..44e97f2d378d 100644 --- a/spec/std/http/params_spec.cr +++ b/spec/std/http/params_spec.cr @@ -17,6 +17,7 @@ module HTTP {"foo", {"foo" => [""]}}, {"foo=&bar", {"foo" => [""], "bar" => [""]}}, {"bar&foo", {"bar" => [""], "foo" => [""]}}, + {"foo=bar=qux", {"foo" => ["bar=qux"]}}, }.each do |(from, to)| it "parses #{from}" do Params.parse(from).should eq(Params.new(to)) diff --git a/src/http/params.cr b/src/http/params.cr index 4c49046c977a..7b61d2ec0fec 100644 --- a/src/http/params.cr +++ b/src/http/params.cr @@ -35,6 +35,7 @@ module HTTP buffer = IO::Memory.new i = 0 + first_equal = true bytesize = query.bytesize while i < bytesize byte = query.unsafe_byte_at(i) @@ -42,9 +43,14 @@ module HTTP case char when '=' - key = buffer.to_s - buffer.clear - i += 1 + if first_equal + key = buffer.to_s + buffer.clear + i += 1 + first_equal = false + else + i = decode_one_www_form_component query, bytesize, i, byte, char, buffer + end when '&', ';' value = buffer.to_s buffer.clear @@ -56,6 +62,7 @@ module HTTP end key = nil + first_equal = true i += 1 else i = decode_one_www_form_component query, bytesize, i, byte, char, buffer