I had a rather long session of investigation on the last weekend. I was fiddling around with a new Ruby 1.9 app and the nightmare what’s called “compat issues”. Almost all of them were caused by Ruby’s brand new encoding handling. One by one, I solved all of them, but one elusive son of a bug kept coming back.
It was “INVALID BYTE SEQUENCE IN US-ASCII”, it only happened when multibyte characters were present in the Haml template. Traces were pointing to engine.rb, a line where a regexp match took place. Checking the involved variables revealed that the template’s source had US-ASCII encoding which is the last fallback default, if no other encoding could be derived from the environment or set explicitly somewhere in the code. Haml raised because it tried to match against a single byte encoding and it encountered multibyte characters instead.
After some investigation, it was clear that Apache did not pick up the proper environment variables for ruby when they were launched by Passenger’s application spawner, nor these variables could be set bySetEnv and/or PassEnv directives.
Altough on OSX Leopard there is a way to set the above variables, so that the spawned ruby processes will pick them up properly, but it’s kinda hacky: you have to edit Apache’s lauchd jobfile file, which by default resides at /System/Library/LaunchDaemons/org.apache.httpd.plist, and add something like this:
<key>EnvironmentVariables</key> <dict> <key>LANG</key> <string>hu_HU.UTF-8</string> <key>LC_CTYPE</key> <string>hu_HU.UTF-8</string> </dict>
Now after an Apace restart ruby processes spawned by Passenger should properly report external encoding.
The detailed story and some followup is here on the Phusion Passenger issue tracker, if you are interested.
Nem csak a kód kap itt szerepet, de az is. Kéne blogolni, vagyis írhatnék az van, csak basz az ideg is meg minden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs # config.load_paths += %W( #{RAILS_ROOT}/extras ) # Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" config.gem 'thoughtbot-clearance', :lib => 'clearance', :source => 'http://gems.github.com', :version => '>= 0.4.7' config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => "http://gems.github.com", :version => '>= 2.9.1' config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => "http://gems.github.com", :version => '>= 1.1.5' config.gem 'configatron', :lib => 'configatron', :version => '>= 2.2' |