Skip to content

Commit 6e1e869

Browse files
authored
Merge pull request #822 from rdimartino/rd/fix-821
Fix multipart with files in binary mode and fields including non-ASCII characters
2 parents bcc3e50 + 4dcc0db commit 6e1e869

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/httparty/request/body.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def normalize_query(query)
8383
def content_body(object)
8484
if file?(object)
8585
object = (file = object).read
86+
object.force_encoding(Encoding::UTF_8) if object.respond_to?(:force_encoding)
8687
file.rewind if file.respond_to?(:rewind)
8788
end
8889

spec/httparty/request/body_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@
137137
it { is_expected.to eq multipart_params }
138138

139139
end
140+
141+
context 'when file is binary data and params contain non-ascii characters' do
142+
let(:file) { File.open('spec/fixtures/tiny.gif', 'rb') }
143+
let(:params) do
144+
{
145+
user: "Jöhn Döé",
146+
enabled: true,
147+
avatar: file,
148+
}
149+
end
150+
151+
it { expect { subject }.not_to raise_error }
152+
end
140153
end
141154
end
142155
end

0 commit comments

Comments
 (0)