Bug #5176
closedUTF-8以外でpsychを使用し、YAML.dumpを実行するとエラーが発生する
Description
Windows環境(mingw)、Linux環境において、添付したファイルで現象が発生します。
libyamlが「YAMLで使用する文字列はUTF-8である」ことを主張するのが原因かと思います。
Stringをdumpする前にUTF-8に変換する作業をライブラリですべきではないでしょうか。
現状、私は添付したファイルのコメントアウトした箇所を有効にすることで、問題を回避しています。
Files
        
           Updated by naruse (Yui NARUSE) about 14 years ago
          Updated by naruse (Yui NARUSE) about 14 years ago
          
          
        
        
      
      - Status changed from Open to Assigned
- Assignee set to tenderlovemaking (Aaron Patterson)
libyamlが「YAMLで使用する文字列はUTF-8である」ことを主張するのが原因かと思います。
これは以下の通り規格が UTF-8 と UTF-16 しかないと言っているので libyaml は正しいと思います。
A YAML processor must support the UTF-16 and UTF-8 character encodings.
If a character stream does not begin with a byte order mark (#FEFF), the character encoding shall be UTF-8.
http://yaml.org/spec/1.1/#id868742
Stringをdumpする前にUTF-8に変換する作業をライブラリですべきではないでしょうか。
うーん、一度変換するともう戻らないのでどうなんでしょうかね。
Encoding.default_internal が指定されているときは変換したほうが良いとは思います。
        
           Updated by shyouhei (Shyouhei Urabe) about 14 years ago
          Updated by shyouhei (Shyouhei Urabe) about 14 years ago
          
          
        
        
      
      戻んないような変換が発生しそうな時はEncoding::InvalidByteSequenceErrorでいいんじゃないかなあ
        
           Updated by naruse (Yui NARUSE) about 14 years ago
          Updated by naruse (Yui NARUSE) about 14 years ago
          
          
        
        
      
      Shyouhei Urabe wrote:
戻んないような変換が発生しそうな時はEncoding::InvalidByteSequenceErrorでいいんじゃないかなあ
InvalidByteSequence はある String の内容であるバイト列がそのエンコーディングとして正しくない時の例外なので、
不可逆変換の時は意味的にちょっと違いますね。
何か一つ指定したらできるくらいのノリがいいかなぁと思っているんですが、SQLite とかでも黙って変換しちゃうので、
YAML 使うという時点でそういうもんだってことでもいいかなとも。
        
           Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
      
      If you use the psych gem, I think it will fix this. Psych should automatically encode to UTF-8, but I think I added that after 1.9.2 was released.
Can you try with the Psych gem please?
Here is a test case I am using: https://gist.github.com/1144463
        
           Updated by hannibal (Masafumi Kiribayashi) about 14 years ago
          Updated by hannibal (Masafumi Kiribayashi) about 14 years ago
          
          
        
        
      
      Thanks Aaron!
I tried Psych gem on Linux and Windows, your test was passed.
And my sample code ran with no errors.
        
           Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          Updated by tenderlovemaking (Aaron Patterson) about 14 years ago
          
          
        
        
      
      - Status changed from Assigned to Closed
- Target version changed from 1.9.2 to 1.9.3
- % Done changed from 0 to 100
Thank you for testing! The fix is in trunk, and should be in 1.9.3 as well. I will close this now.