From: Urabe Shyouhei Date: 2007-02-27T21:00:02+09:00 Subject: [ruby-dev:30439] Re: MIME decoding confused by non-MIME characters -devに振ってみる。 Brian Candler wrote: > Could someone who has bleeding-edge Ruby installed please test the > following? > > irb(main):001:0> RUBY_VERSION > => "1.8.5" > irb(main):002:0> a = "b2s=" > => "b2s=" > irb(main):003:0> b = "\xef\xbb\xbf" + a > => "\357\273\277b2s=" > irb(main):004:0> a.unpack("m") > => ["ok"] > irb(main):005:0> b.unpack("m") > => ["$\000\e\332"] > > That is, non-printable characters (here a UTF8-encoded BOM) are causing MIME > unpack to return garbage. > これどうすべきだと思います? NKFですら irb(main):001:0> NKF.nkf "-W8emB", "\xef\xbb\xbfb2s=" => "\e" こんな感じなので、「そういうものです」と言い切ってしまうのもありといえば ありな気がしますが... (参考)他の言語ではどうなってるかというと % perl -mMIME::Base64 -e'print MIME::Base64::decode_base64("\xef\xbb\277b2s=")' ok % python Python 2.4.4 (#2, Jan 13 2007, 17:50:26) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from base64 import b64decode >>> b64decode("\xef\xbb\277b2s=") 'ok' >>> % php -r 'echo base64_decode("\xef\xbb\277b2s=");' ok