From: Aaron Patterson Date: 2010-11-03T11:21:19+09:00 Subject: [ruby-core:33029] Re: [Ruby 1.9-Bug#4010] YAML fails to roundtrip non ASCII String --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 02, 2010 at 09:58:27PM +0900, Heesob Park wrote: > Issue #4010 has been updated by Heesob Park. >=20 >=20 > The same result with psych. >=20 > $ ruby -v -ryaml -e 'YAML::ENGINE.yamler =3D "psych"; s=3D"=ED=95=9C=EA= =B8=80";pYAML.load(YAML.dump(s))=3D=3Ds' > ruby 1.9.3dev (2010-11-02 trunk 29667) [i686-linux] > /usr/local/lib/ruby/1.9.1/psych/deprecated.rb:79: warning: method redefin= ed; discarding old to_yaml_properties > /usr/local/lib/ruby/1.9.1/syck/rubytypes.rb:13: warning: previous definit= ion of to_yaml_properties was here > false >=20 > FYI the current encoding is 'EUC-KR'. > I know it works when the encoding is 'UTF-8'. I think the problem is that your default_internal encoding isn't being set. YAML is usually stored as UTF-8, but psych will automatically transcode the string to whatever your default_internal encoding is set to. Maybe this script will help illustrate the problem: # coding: utf-8 =20 require 'psych' =20 eucjp =3D "=E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF=EF=BC=81".enco= de('EUC-JP') string =3D Psych.load(Psych.dump(eucjp)) =20 p string.encoding # =3D> # p eucjp =3D=3D string # =3D> false =20 Encoding.default_internal =3D 'EUC-JP' =20 string =3D Psych.load(Psych.dump(eucjp)) p string.encoding # =3D> # p eucjp =3D=3D string # =3D> true Try running your Ruby like this: $ ruby -EEUC-KR:EUC-KR -v -ryaml -e 'YAML::ENGINE.yamler =3D "psych"; s= =3D"=ED=95=9C=EA=B8=80";pYAML.load(YAML.dump(s))=3D=3Ds' --=20 Aaron Patterson http://tenderlovemaking.com/ --ReaqsoxgOBHFXBhH Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJM0MVNAAoJEJUxcLy0/6/GbKgH/1Xe/fVmVoMxM5WybOEUgxvX MOJ1n31m5i1JDp4/V2xtBjtdivfzmZ8PDn37qv0Jo3/rybBVQLAOUKHBTwVA+RNd p8UK1zStoMnLRufHsFkcUsSWz5ss2sB8LNm4r+1oLye870ygcWhi9c64Lkn+kNes Z1rr5ez+WoJ071cm/cDPI6lk7KpjtbhFa3yQG5ZbOUnAJyB2oJndOVPdozEgIVzL WCT1p6FZ1QcJl4wkWUubeqHx0XylzdlAmHOY3Ydl6zyp6Xk+7SaZssLXiNEC96EK I6QYMwF1vxmosbecDvMqV693oRhprgbbkGIMaY5VimlqgY++P2AaC5epGpgRdds= =JltE -----END PGP SIGNATURE----- --ReaqsoxgOBHFXBhH--