utils.rb#build_primitive_part: incompatible character encodings: UTF-8 and ASCII-8BIT
rocket-turtle opened this issue · 4 comments
Error with File upload and UTF-8 Parameters.
In my Project a different test failed with the Patch from #309.
This test is failing with and without the Patch so I'm not sure if it is directly related to the other issue.
git diff for a failing spec
diff --git a/spec/rack/test/utils_spec.rb b/spec/rack/test/utils_spec.rb
index 3365c0c..339db65 100644
--- a/spec/rack/test/utils_spec.rb
+++ b/spec/rack/test/utils_spec.rb
@@ -170,7 +170,7 @@ describe 'Rack::Test::Utils.build_multipart' do
it 'builds nested multipart bodies with UTF-8 data' do
files = Rack::Test::UploadedFile.new(multipart_file('mb.txt'))
- data = Rack::Test::Utils.build_multipart('people' => [{ 'submit-name' => "\u1234", 'files' => files }], 'foo' => %w[1 2])
+ data = Rack::Test::Utils.build_multipart('people' => [{ 'files' => files, 'submit-name' => "\u1234" }], 'foo' => %w[1 2])
options = {
'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Test::MULTIPART_BOUNDARY}",
bundle exec ruby spec/rack/test/utils_spec.rb -n /test_0006_builds/
Run options: -n /test_0006_builds/ --seed 40265
# Running:
E
Finished in 0.001990s, 502.5126 runs/s, 0.0000 assertions/s.
1) Error:
Rack::Test::Utils.build_multipart#test_0006_builds nested multipart bodies with UTF-8 data:
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:129:in `build_primitive_part'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:116:in `block (2 levels) in _build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:112:in `map'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:112:in `block in _build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `each'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `map'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `_build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:109:in `block (2 levels) in _build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:106:in `each'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:106:in `block in _build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `each'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `map'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:104:in `_build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:98:in `build_parts'
/Users/jonas.schoeler/rails/gem/rack-test/lib/rack/test/utils.rb:55:in `build_multipart'
spec/rack/test/utils_spec.rb:173:in `block (2 levels) in <main>'
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
I have the same error being thrown in tests that worked fine in 1.1.0
. It looks like when the value Café Bean
is passed as a param value with files uploaded then the Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
.
Thanks for the report. I'll work on this shortly and get 2.0.2 released after it is fixed.
rack-test 2.0.2 has been released with this fix.
Thank you again for the fast fixes. All our tests are green now.
Really appreciate your work.