diff --git a/lib/rack/test/utils.rb b/lib/rack/test/utils.rb index d1f74568..aea7193b 100644 --- a/lib/rack/test/utils.rb +++ b/lib/rack/test/utils.rb @@ -152,7 +152,6 @@ def build_file_part(buffer, parameter_name, uploaded_file) # Handle old versions of Capybara::RackTest::Form::NilUploadedFile if uploaded_file.respond_to?(:set_encoding) - uploaded_file.set_encoding(Encoding::BINARY) uploaded_file.append_to(buffer) end diff --git a/spec/rack/test/utils_spec.rb b/spec/rack/test/utils_spec.rb index 090276d3..7771909c 100644 --- a/spec/rack/test/utils_spec.rb +++ b/spec/rack/test/utils_spec.rb @@ -78,6 +78,18 @@ describe 'Rack::Test::Utils.build_multipart' do include Rack::Test::Utils + it 'preserves the source encoding of uploaded StringIO content' do + source = +"café" + file = Rack::Test::UploadedFile.new( + StringIO.new(source), + original_filename: 'content.txt' + ) + + Rack::Test::Utils.build_multipart('file' => file) + + source.encoding.must_equal Encoding::UTF_8 + end + it 'builds multipart bodies' do files = Rack::Test::UploadedFile.new(multipart_file('foo.txt')) data = Rack::Test::Utils.build_multipart('submit-name' => 'Larry', 'files' => files)