mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Fix multipart line-breaks and quotes
This commit is contained in:
parent
806278e7f2
commit
a3d8528fc3
2 changed files with 22 additions and 22 deletions
|
@ -30,17 +30,17 @@ module HTTParty
|
||||||
normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
||||||
|
|
||||||
multipart = normalized_params.inject('') do |memo, (key, value)|
|
multipart = normalized_params.inject('') do |memo, (key, value)|
|
||||||
memo += "--#{boundary}\n"
|
memo += "--#{boundary}\r\n"
|
||||||
memo += "Content-Disposition: form-data; name='#{key}'"
|
memo += %(Content-Disposition: form-data; name="#{key}")
|
||||||
memo += "; filename='#{File.basename(value)}'" if file?(value)
|
memo += %(; filename="#{File.basename(value)}") if file?(value)
|
||||||
memo += "\n"
|
memo += "\r\n"
|
||||||
memo += "Content-Type: application/octet-stream\n" if file?(value)
|
memo += "Content-Type: application/octet-stream\r\n" if file?(value)
|
||||||
memo += "\n"
|
memo += "\r\n"
|
||||||
memo += file?(value) ? value.read : value
|
memo += file?(value) ? value.read : value
|
||||||
memo += "\n"
|
memo += "\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
multipart += "--#{boundary}--\n"
|
multipart += "--#{boundary}--\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_file?(hash)
|
def has_file?(hash)
|
||||||
|
|
|
@ -32,20 +32,20 @@ RSpec.describe HTTParty::Request::Body do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
let(:multipart_params) do
|
let(:multipart_params) do
|
||||||
"--------------------------c772861a5109d5ef\n" \
|
"--------------------------c772861a5109d5ef\r\n" \
|
||||||
"Content-Disposition: form-data; name='user[avatar]'; filename='tiny.gif'\n" \
|
"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"tiny.gif\"\r\n" \
|
||||||
"Content-Type: application/octet-stream\n" \
|
"Content-Type: application/octet-stream\r\n" \
|
||||||
"\n" \
|
"\r\n" \
|
||||||
"GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;\n" \
|
"GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;\r\n" \
|
||||||
"--------------------------c772861a5109d5ef\n" \
|
"--------------------------c772861a5109d5ef\r\n" \
|
||||||
"Content-Disposition: form-data; name='user[first_name]'\n" \
|
"Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \
|
||||||
"\n" \
|
"\r\n" \
|
||||||
"John\n" \
|
"John\r\n" \
|
||||||
"--------------------------c772861a5109d5ef\n" \
|
"--------------------------c772861a5109d5ef\r\n" \
|
||||||
"Content-Disposition: form-data; name='user[last_name]'\n" \
|
"Content-Disposition: form-data; name=\"user[last_name]\"\r\n" \
|
||||||
"\n" \
|
"\r\n" \
|
||||||
"Doe\n" \
|
"Doe\r\n" \
|
||||||
"--------------------------c772861a5109d5ef--\n"
|
"--------------------------c772861a5109d5ef--\r\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq multipart_params }
|
it { is_expected.to eq multipart_params }
|
||||||
|
|
Loading…
Reference in a new issue