Ruby 1.9.3 and Encoding Trouble

Character encodings are a perennial source of trouble. Simple calculations such as string comparison, collation, and even length are a function of the encoding. Reliably translating string encodings is, as a practical matter, frequently painful. The primary string encoding functions in Ruby 1.9.3 are in the core Encoding class. James Gray has a helpful blog post that provides an overview of string encoding in Ruby 1.9.

If you use the :universal_newline option to String.encode, be aware that it may break your code if you use Ruby 1.9.3-p194. This gist https://gist.github.com/2869891 has a small code snippet that returns successfully when run with Ruby 1.9.3-p0 but fails with Ruby 1.9.3-p194 with the error:

[sourcecode language=”ruby”]
UTF-8
x.rb:7:in `encode’: code converter not found (universal_newline) (Encoding::ConverterNotFoundError)
from x.rb:7:in `’
[/sourcecode]

Post a Comment