Rack upload file Encoding::CompatibilityError #273

Closed
le0pard opened this Issue Nov 22, 2011 · 5 comments

Projects

None yet

4 participants

@le0pard
le0pard commented Nov 22, 2011

Hello to all. Try to load file in rails with name of file "мир %D0есть.jpg". Have such error.

Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT
/Users/leo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/uri/common.rb:912:in `gsub'
/Users/leo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/uri/common.rb:912:in `decode_www_form_component'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/utils.rb:37:in `unescape'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart/parser.rb:130:in `get_filename'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart/parser.rb:92:in `get_current_head_and_filename_and_content_type_and_name_and_body'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart/parser.rb:19:in `block in parse'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart/parser.rb:17:in `loop'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart/parser.rb:17:in `parse'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/multipart.rb:25:in `parse_multipart'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/request.rb:306:in `parse_multipart'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/request.rb:182:in `POST'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/methodoverride.rb:15:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/runtime.rb:17:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/activesupport-3.1.1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/lock.rb:15:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:53:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/airbrake-3.0.4/lib/airbrake/user_informer.rb:12:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/railties-3.1.1/lib/rails/engine.rb:456:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/lint.rb:48:in `_call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/lint.rb:36:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/showexceptions.rb:24:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/commonlogger.rb:20:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/chunked.rb:41:in `call'
/Users/leo/programs/projects/adility_console/vendor/gems/rack/lib/rack/content_length.rb:14:in `call'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:528:in `process_client'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:600:in `worker_loop'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:485:in `spawn_missing_workers'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:135:in `start'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/gems/unicorn-4.1.1/bin/unicorn:121:in `<top (required)>'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/bin/unicorn:19:in `load'
/Users/leo/.rvm/gems/ruby-1.9.3-p0@adility_console_gems/bin/unicorn:19:in `<main>'

How to fix this error (except rename file)?

Gems:
rack (1.3.5)
rails (3.1.1)
ruby (1.9.3)
unicorn (4.1.1)

@josh
Contributor
josh commented Nov 30, 2011

Rack doesn't make any assumptions about the decoded params. You'll need to specify that yourself. You probably just want to set your default external encoding to utf8 or whatever encoding your using on your FS.

@josh josh closed this Nov 30, 2011
@le0pard
le0pard commented Nov 30, 2011

This file located on Linux ext4 file system, loading on linux server also. System have encoding UTF-8 by default. Form on rails app have hidden field utf8 with value ✓. Content-Type UTF-8. What I miss?

@hannesg
Contributor
hannesg commented Nov 30, 2011

Maybe you miss that %D0 is an invalid utf-8 character?

@le0pard
le0pard commented Nov 30, 2011

ok, thanks.

@kuon
kuon commented Dec 5, 2011

I have the same problem when a file with an accent is uploaded.

[2011-12-05 16:00:10] ERROR ArgumentError: invalid byte sequence in UTF-8
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:129:in `gsub'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:129:in `get_filename'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:92:in `get_current_head_and_filename_and_content_type_and_name_and_body'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:19:in `block in parse'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:17:in `loop'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart/parser.rb:17:in `parse'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/multipart.rb:25:in `parse_multipart'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/request.rb:306:in `parse_multipart'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/request.rb:182:in `POST'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/methodoverride.rb:15:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/runtime.rb:17:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/lock.rb:15:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/engine.rb:456:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/content_length.rb:14:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/rack/log_tailer.rb:14:in `call'
    /Users/kuon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/handler/webrick.rb:59:in `service'
    /Users/kuon/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /Users/kuon/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /Users/kuon/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

As my code is not called, I'm not sure if I can do anything about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment