From: Nobuyoshi Nakada Date: 2008-03-03T00:21:28+09:00 Subject: [ruby-dev:33959] Re: --encoding affects script encoding なかだです。 At Sun, 2 Mar 2008 00:31:01 +0900, sheepman wrote in [ruby-dev:33955]: > shebang を検査する前に一旦 IO エンコーディングを セットしておくべき > なんだと思います。 コミットしましたが、IO#ungetcでのエンコーディングの扱いが抜けて いることに気づきました。 Index: io.c =================================================================== --- io.c (revision 15671) +++ io.c (working copy) @@ -2430,4 +2430,5 @@ VALUE rb_io_ungetc(VALUE io, VALUE c) { + rb_encoding *enc; rb_io_t *fptr; @@ -2437,11 +2438,15 @@ rb_io_ungetc(VALUE io, VALUE c) if (FIXNUM_P(c)) { int cc = FIX2INT(c); - rb_encoding *enc = io_read_encoding(fptr); char buf[16]; - c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc)); + c = rb_str_new(buf, rb_enc_mbcput(cc, buf, io_read_encoding(fptr))); + enc = fptr->enc2; } else { SafeStringValue(c); + enc = io_input_encoding(fptr); + } + if (enc && enc != rb_enc_get(c)) { + c = rb_funcall(c, id_encode, 1, rb_enc_from_encoding(enc)); } io_ungetc(c, fptr); -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦