diff --git a/Gemfile b/Gemfile index c86cabb..e7e94e5 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ group :test do end group :doc do - gem "redcarpet" + gem "redcarpet", :platform => :mri gem "yard" end diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index 61c72ad..30d556d 100644 --- a/lib/http/form_data/composite_io.rb +++ b/lib/http/form_data/composite_io.rb @@ -9,7 +9,7 @@ class CompositeIO # @param [Array] ios Array of IO objects def initialize(ios) @index = 0 - @buffer = String.new + @buffer = "".b @ios = ios.map do |io| if io.is_a?(String) StringIO.new(io) @@ -29,14 +29,16 @@ def initialize(ios) # # @return [String, nil] def read(length = nil, outbuf = nil) - outbuf = outbuf.to_s.replace("") + outbuf = outbuf.to_s.clear + # buffer in JRuby is sometimes US-ASCII, force to ASCII-8BIT + outbuf.force_encoding(Encoding::BINARY) while current_io current_io.read(length, @buffer) - outbuf << @buffer + outbuf << @buffer.force_encoding(Encoding::BINARY) if length - length -= @buffer.length + length -= @buffer.bytesize break if length.zero? end diff --git a/lib/http/form_data/multipart/param.rb b/lib/http/form_data/multipart/param.rb index 080b9e2..5972752 100644 --- a/lib/http/form_data/multipart/param.rb +++ b/lib/http/form_data/multipart/param.rb @@ -62,7 +62,7 @@ def self.coerce(data) private def header - header = String.new + header = "".b header << "Content-Disposition: form-data; #{parameters}#{CRLF}" header << "Content-Type: #{content_type}#{CRLF}" if content_type header << CRLF