开发者

Ruby 1.9.2 and Rails 3.0 UTF-8 madness [duplicate]

开发者 https://www.devze.com 2023-03-19 03:33 出处:网络
This question already has answers here: Why does Rails 3 think xE2x80x89 means â x80 x89 (3 answers)
This question already has answers here: Why does Rails 3 think xE2x80x89 means â x80 x89 (3 answers) Closed 2 years ago.

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消