Skip to content

Instantly share code, notes, and snippets.

@senny
Last active December 18, 2015 22:49
Show Gist options
  • Save senny/5857653 to your computer and use it in GitHub Desktop.
Save senny/5857653 to your computer and use it in GitHub Desktop.
Wierd problem when an exception is raised inside a template that has a UTF-8 encoded identifier. Using module_eval with an UTF-8 filename as in (https://github.com/rails/rails/blob/master/actionview/lib/action_view/template.rb#L295), will result in ASCII-8Bit entries in the `e.backtrace` array.
module EncodingBug
end
filename = ARGV[0]
puts "using encoding: #{filename.encoding}"
EncodingBug.module_eval "def self.say; raise end", filename, 1
begin
EncodingBug.say
rescue => e
frame = e.backtrace.first
puts "frame: #{frame}"
puts "backtrace encoding: #{frame.encoding}"
end
activesupport :: (master*) » ruby reproduction.rb ä
using encoding: UTF-8
frame: ä:1:in `say'
backtrace encoding: ASCII-8BIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment