"\xC2" to UTF-8 in conversion from ASCII-8BIT to UTF-8
Asked Answered
M

1

5

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

Morville answered 25/4, 2013 at 15:28 Comment(0)
M
11

It turns out the page had an invalid character (an interpunct '·'), which I found out with the following code (credits to 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

After running this code, I could find the problematic characters with a simple git diff and moved the code to a helper file with # encoding: utf-8 at the top. I'm not sure why this doesn't fail with MRI but it should since I'm not specifying the encoding of the haml file.

Morville answered 25/4, 2013 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.