From 2a86ded85a46707c483fe5f863a0143bd30b89ef Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 18 Dec 2017 09:54:39 +0200 Subject: [PATCH 1/7] using buffer string in binary encoding, as String.new is utf-8, and you'll need binary for payload --- lib/http/form_data/composite_io.rb | 2 +- lib/http/form_data/multipart/param.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index 61c72ad..67e9261 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) 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 From 621e18ec286b7eb30fefa9e13b48e7d71cbda02b Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 18 Dec 2017 09:55:41 +0200 Subject: [PATCH 2/7] use String#bytesize, as #length returns the length size in its encoding --- lib/http/form_data/composite_io.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index 67e9261..401a18f 100644 --- a/lib/http/form_data/composite_io.rb +++ b/lib/http/form_data/composite_io.rb @@ -36,7 +36,7 @@ def read(length = nil, outbuf = nil) outbuf << @buffer if length - length -= @buffer.length + length -= @buffer.bytesize break if length.zero? end From 3d97b8392b43718979f7cbe522f807e39b7b278b Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 18 Dec 2017 09:56:23 +0200 Subject: [PATCH 3/7] use String#clear instead of String#replace, as the latter changes the encoding --- lib/http/form_data/composite_io.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index 401a18f..e2c1dc5 100644 --- a/lib/http/form_data/composite_io.rb +++ b/lib/http/form_data/composite_io.rb @@ -29,7 +29,7 @@ def initialize(ios) # # @return [String, nil] def read(length = nil, outbuf = nil) - outbuf = outbuf.to_s.replace("") + outbuf = outbuf.to_s.clear while current_io current_io.read(length, @buffer) From 9a1b9116c0bd88be53cbbfb62e2c7039de685f46 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 18 Dec 2017 09:56:51 +0200 Subject: [PATCH 4/7] do not use rercarpet for jruby --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c86cabb..9084966 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 From 3bc378740c660292ee671ec8f4f6399f69364570 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 18 Dec 2017 13:43:56 +0200 Subject: [PATCH 5/7] jruby accusing something other than ASCII-8bit sometimes (US-ASCII), force binary here --- lib/http/form_data/composite_io.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index e2c1dc5..7e48f89 100644 --- a/lib/http/form_data/composite_io.rb +++ b/lib/http/form_data/composite_io.rb @@ -30,6 +30,8 @@ def initialize(ios) # @return [String, nil] def read(length = nil, outbuf = nil) 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) From f08d80ce1df1ba924e2ce04a93a28cea480844ff Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 8 Jan 2018 20:00:17 +0000 Subject: [PATCH 6/7] hash rocketz --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 9084966..e7e94e5 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ group :test do end group :doc do - gem "redcarpet", platform: :mri + gem "redcarpet", :platform => :mri gem "yard" end From eeff06c789352fc87bd4351476318e8fc7f55fe9 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Mon, 29 Jan 2018 20:15:42 +0000 Subject: [PATCH 7/7] forcing the buffer to binary, as the buffer encoding might change --- lib/http/form_data/composite_io.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/form_data/composite_io.rb b/lib/http/form_data/composite_io.rb index 7e48f89..30d556d 100644 --- a/lib/http/form_data/composite_io.rb +++ b/lib/http/form_data/composite_io.rb @@ -35,7 +35,7 @@ def read(length = nil, outbuf = nil) while current_io current_io.read(length, @buffer) - outbuf << @buffer + outbuf << @buffer.force_encoding(Encoding::BINARY) if length length -= @buffer.bytesize