strongbox
strongbox copied to clipboard
Encoding::CompatibilityError
I have a problem with german umlauts in secured datafields. When I saved "grün" (english: green) in a mysql database field, and show it again, i get the following Error:
Encoding::CompatibilityError in Addressees#show
incompatible character encodings: UTF8 and ASCII-8BIT
I had to use force_encode('utf8') for each field.
It this an error in strongbox? Why are the encrypted fields decrypted in ascii-8bit?
The issue is how Ruby itself handles the decrypted field. "ASCII-8BIT" is an alias for "BINARY" and means "raw-bytes". Ruby chooses this because it doesn't know what the encoding of the field was before it was encrypted. So, yes you have to use force_encode to set the encoding if you need more than ASCII.
The fix would be for the Ruby RSA to use the default encoding and provide a way to override it, like Ruby IO does.
There's a good writeup on Ruby 1.9 encoding issues here:
http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/