From 5a43908c7414996354ca427354d98d789e0210e7 Mon Sep 17 00:00:00 2001 From: Bryan Ash Date: Tue, 13 Jan 2009 14:42:43 -0600 Subject: [PATCH] Explicitly read as binary in multipart_body for Windows [#1065 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_controller/integration.rb | 2 +- .../request/multipart_params_parsing_test.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index 08b54658ee..5b08e30d49 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -431,7 +431,7 @@ module ActionController def multipart_body(params, boundary) multipart_requestify(params).map do |key, value| if value.respond_to?(:original_filename) - File.open(value.path) do |f| + File.open(value.path, "rb") do |f| f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding) <<-EOF diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb index 03ab164972..ce28ff46fe 100644 --- a/actionpack/test/controller/request/multipart_params_parsing_test.rb +++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb @@ -3,11 +3,10 @@ require 'abstract_unit' class MultipartParamsParsingTest < ActionController::IntegrationTest class TestController < ActionController::Base class << self - attr_accessor :last_request_parameters, :last_request_type + attr_accessor :last_request_parameters end def parse - self.class.last_request_type = ActionController::Base.param_parsers[request.content_type] self.class.last_request_parameters = request.request_parameters head :ok end @@ -21,7 +20,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest def teardown TestController.last_request_parameters = nil - TestController.last_request_type = nil end test "parses single parameter" do @@ -103,11 +101,13 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest assert_equal 19756, files.size end - test "uploads and parses parameters" do + test "uploads and reads binary file" do with_test_routing do - params = { :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/mona_lisa.jpg", "image/jpg") } - post '/parse', params, :location => 'blah' - assert_equal(:multipart_form, TestController.last_request_type) + fixture = FIXTURE_PATH + "/mona_lisa.jpg" + params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") } + post '/read', params + expected_length = 'File: '.length + File.size(fixture) + assert_equal expected_length, response.content_length end end