Ruby 1.9.2 and Rails 3.0 UTF-8 madness [duplicate]
My previous question is answered but there's a few more things I don't understand.
I have a yaml file which contains a field with a utf-8 character:
:name: O\xE2\x80\x99Reilly
When I load the yaml in irb:
>puts name.encoding => UTF-8
>name => "O\xE2\x80\x99Reilly"
>puts name => O’Reilly
When I load the yaml in Rails:
>puts name.encoding => UTF-8
>puts name => Oâ[80][99]Reilly
>puts name.force_encoding('utf-8') => Oâ[80][99]Reilly开发者_如何转开发
>puts Iconv('iso-8859-1', '', name) => O’Reilly
Q3: Why does rails print it's initial utf-8 string as if it's iso-8859-1, and the string converted to iso-8859-1 as if it's utf-8?
Your config/application.rb
file in rails probably has this:
config.encoding = "utf-8"
This is only an answer to the first Q and may or may not have any relevance to the next 2 :)
精彩评论