I have a rails project that runs fine with MRI 1.9.3. When I try to run with Rubinius I get this error in app/views/layouts/application.html.haml
:
"\xC2" to UTF-8 in conversion from ASCII-8BIT to UTF-8
I have a rails project that runs fine with MRI 1.9.3. When I try to run with Rubinius I get this error in app/views/layouts/application.html.haml
:
"\xC2" to UTF-8 in conversion from ASCII-8BIT to UTF-8
事实证明该页面有一个无效字符(一个interpunct '·'),我通过以下代码发现了它(归功于this gist and this question):
lines = IO.readlines("app/views/layouts/application.html.haml").map do |line|
line.force_encoding('ASCII-8BIT').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
end
File.open("app/views/layouts/application.html.haml", "w") do |file|
file.puts(lines)
end
运行这段代码后,我可以用一个简单的方法找到有问题的字符,并将代码移动到顶部git diff
的帮助文件中。# encoding: utf-8
我不确定为什么 MRI 不会失败,但它应该因为我没有指定 haml 文件的编码。