[katello-devel] ruby 1.9, rails, and encodings

Dmitri Dolguikh dmitri at redhat.com
Mon Oct 29 12:41:34 UTC 2012


Hey all,

Ruby 1.9 is *much* less lax about String encodings, and there a few 
basic things everybody should know to avoid surprises (esp. when 
switching back and forth between 1.8 and 1.9).


In the absence of "magic comment" (pls. see below) Ruby 1.9 assumes that 
source file encoding is US-ASCII. This is 7-bit encoding (true 7 bit 
ASCII) and is therefore incompatible with extended character sets. You 
can add a "magic comment" in the beginning of the source code file to 
mark the encoding:

# encode: utf-8

Please note that this allows for use of extended characters set 
characters in variable, method, etc names. Probably not a good idea, 
however (ruby 1.8 for example, will be *very* disappointed).

Under 1.9, when inside rails, it's safe to assume that strings you are 
dealing with are utf-8 encoded (you can check the values of 
Encoding.default_internal and Encoding.default_external if you are 
curious). Rails also takes care of handling of incoming non-utf-encoded 
strings (such as form data) into utf when the encoding of those strings 
is incorrectly specified, or not specified at all. Please see [1] for 
more details.

Let me know if you have any questions,
-d


[1]. http://yehudakatz.com/2010/05/17/encodings-unabridged/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/katello-devel/attachments/20121029/73427536/attachment.htm>


More information about the katello-devel mailing list