Difference between revisions of "incompatible character encodings: UTF-8 and ASCII-8BIT/2011-11-13 Askru post"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(Created page with "[https://stackanswers.net/questions/actionview-template-error-incompatible-character-encodings-utf-8-and-ascii-8bit This post] on stackanswers.net aka Askru may offer some clu...")
 
(note: can't find where this line is)
 
Line 1: Line 1:
 
[https://stackanswers.net/questions/actionview-template-error-incompatible-character-encodings-utf-8-and-ascii-8bit This post] on stackanswers.net aka Askru may offer some clues. I've translated the first answer, which seems useful, from Russian with Google Translate.
 
[https://stackanswers.net/questions/actionview-template-error-incompatible-character-encodings-utf-8-and-ascii-8bit This post] on stackanswers.net aka Askru may offer some clues. I've translated the first answer, which seems useful, from Russian with Google Translate.
 +
 +
I cannot, however, find the file where the cited line might be, and can only conclude that it's no longer present in Redmine 3.x.
 
==Translation==
 
==Translation==
 
After doing some debugging, I found out that the problem occurs when using ActionDispatch :: a request object that happens to have strings that are all encoded in [[ASCII-8bit]], regardless of whether my application is encoded in [[UTF-8]] or not. I don’t know why this only happens when using a production server on Linux, but I will assume that this is some kind of ruby, or Rails, since I could not reproduce this error locally. The error occurred precisely because lines like this:
 
After doing some debugging, I found out that the problem occurs when using ActionDispatch :: a request object that happens to have strings that are all encoded in [[ASCII-8bit]], regardless of whether my application is encoded in [[UTF-8]] or not. I don’t know why this only happens when using a production server on Linux, but I will assume that this is some kind of ruby, or Rails, since I could not reproduce this error locally. The error occurred precisely because lines like this:

Latest revision as of 14:24, 10 February 2020

This post on stackanswers.net aka Askru may offer some clues. I've translated the first answer, which seems useful, from Russian with Google Translate.

I cannot, however, find the file where the cited line might be, and can only conclude that it's no longer present in Redmine 3.x.

Translation

After doing some debugging, I found out that the problem occurs when using ActionDispatch :: a request object that happens to have strings that are all encoded in ASCII-8bit, regardless of whether my application is encoded in UTF-8 or not. I don’t know why this only happens when using a production server on Linux, but I will assume that this is some kind of ruby, or Rails, since I could not reproduce this error locally. The error occurred precisely because lines like this:

@current_path = request.env['PATH_INFO']

When this instance variable was printed in the Haml template, it caused an error because the string was encoded in ASCII-8bit instead of UTF-8. To solve this problem, I did the following:

@current_path = request.env['PATH_INFO'].dup.force_encoding(Encoding::UTF_8)

Which forced @current_path to use a duplicate string that was forced into the proper UTF-8 encoding. This error may occur with other data related to a similar request.headers request.