Here's script to reproduce the issue:
Here's output of the script with tilt 1.1:
/tmp/template20101205-22819-1ljrpwf:2:in `concat': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)
from /tmp/template20101205-22819-1ljrpwf:2:in `evaluate_source'
from /usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.1/lib/tilt.rb:254:in `instance_eval'
from /usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.1/lib/tilt.rb:254:in `evaluate_source'
from /usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.1/lib/tilt.rb:195:in `evaluate'
from /usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.1/lib/tilt.rb:128:in `render'
from test.rb:15:in `<main>'
Issue here is that:
Solution in this change is to copy the magic comment to the first line.
It looks like #45 solves the same issue, but this patch might be slightly simpler and more general (because it should also work for other template engines which output magic comment if any).
Fixing Encoding::CompatibilityError with Ruby 1.9 + ERB, by copying m…
…agic comment to the first line so that it works.
Hiroshi: Does this solve the Sinatra issue on Ubuntu?
Ryan: If so, +1 an can we have a new Tilt release some time soon?
Yes, I verified it solves the issue of Encoding::CompatibilityError when multi-byte character is used in both controller and view template (if magic comment is correctly written in both file). I haven't checked original issue reported by Quintus (where one template renders another template), but I guess it's fixed too.
When will this fix be released in a gem?
Marvelous! Gem soon, please!
Was just playing with this patch and Sinatra, and it only seems to work for the first render of the ERB. The second time render() is called, the template seems to have reverted to ASCII-8BIT.
I created a patched script to reproduce the issue:
Fixed in PR #50.
Add magic comments for encoding to method compilation, too.
Also, add test for encoding issues with erb.