k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
980 stars 60 forks source link

Rack::Lint::LintError does not have ASCII-8BIT as its external encoding #158

Closed AlessandroMinali closed 4 years ago

AlessandroMinali commented 4 years ago

Summary: Occuring when using hamlit and POST requests. I made a repo to reproduce the bug: https://github.com/AlessandroMinali/hamlit-bug Switching to use haml the bug disappears. I recently moved to ruby2.7.0 and fresh installed all gems then started noticing this.

Full error backtrace:

Rack::Lint::LintError: rack.input #<StringIO:0x00007ffc1294edf8> does not have ASCII-8BIT as its external encoding
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:21:in `assert'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:380:in `check_input'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:333:in `check_env'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:44:in `_call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:38:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/sinatra-2.0.8.1/lib/sinatra/base.rb:231:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/rack-2.2.3/lib/rack/content_length.rb:17:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/configuration.rb:228:in `call'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/server.rb:713:in `handle_request'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/server.rb:472:in `process_client'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/server.rb:328:in `block in run'
  /Users/alessandro/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
::1 - - [23/Jul/2020:10:45:35 -0400] "POST / HTTP/1.1" 500 52661 0.0294

Haml template:

%h1 Login
%form{action: '/', method: 'post'}
  %input{type: 'text', name: 'name'}
  %input{type: 'submit'}

Ruby version: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]

Hamlit version:

$ hamlit version
2.11.0

Rails/Sinatra version: sinatra (2.0.8.1)

k0kubun commented 4 years ago

Thanks for reporting it with a repository for reproduction.

Unfortunately, I couldn't reproduce the issue on my machine. Could you please also share:

AlessandroMinali commented 4 years ago

Just using a simple string like "test" produces the error for me.

I added the output to the template: https://github.com/AlessandroMinali/hamlit-bug/commit/b6e258737b526609d51b8e0e8878300ab9ade5d4

My result is: ENV['LANG'] == nil and Encoding.default_external == #<Encoding:UTF-8>

Also:

$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
k0kubun commented 4 years ago

Thanks for the additional information. But even with the information I still can't reproduce the problem.

Could you prepare Dockerfile which has an environment similar to yours and reproduces the problem? I'm not familiar with Rack::Lint and it's hard to resolve the issue without a reproductive environment.

AlessandroMinali commented 4 years ago

I did a clean ruby and gem install and the problem has gone away for now. If it comes up again I will provide a dockerfile.

Thanks for the replies.