Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HTTP::Params.parse query string with two '=' #4389

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/std/http/params_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 10 additions & 3 deletions src/http/params.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ module HTTP
buffer = IO::Memory.new

i = 0
first_equal = true
bytesize = query.bytesize
while i < bytesize
byte = query.unsafe_byte_at(i)
char = byte.unsafe_chr

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
Expand All @@ -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
Expand Down