Bug #4281: irb don't start up when Encoding.defalut_internal isn't 'utf-8'
http://redmine.ruby-lang.org/issues/show/4281

ɼ???: Narihiro Nakamura
?????????: Open, ?????: Normal
????????: ext, Target version: 1.9.2
ruby -v: ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]

nari???????

以??????????????????? irb ???起???????????????
 $ ruby -S -E cp932:cp932 irb
 /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/locale.rb:135:in `eval': /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/lc/ja/error.rb:16: invalid multibyte char (UTF-8) (SyntaxError)
 /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/lc/ja/error.rb:16: invalid multibyte char (UTF-8)
 /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/lc/ja/error.rb:16: syntax error, unexpected $end, expecting keyword_end
   def_exception :UnrecognizedSwitch, '????????(%s)????????????????'
                                          ^
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/locale.rb:135:in `real_load'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/locale.rb:125:in `block in load'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/locale.rb:123:in `each'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/locale.rb:123:in `load'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/init.rb:122:in `init_error'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/init.rb:17:in `setup'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:53:in `start'
         from /home/nari/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `<main>'

??????????以????????
 $ cat /tmp/t.rb
 require "irb"
 Encoding.default_internal = "cp932"
 Encoding.default_external = "cp932"
 # path???Ruby????????????????????????????????????????
 path = "/home/nari/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/lc/ja/error.rb"
 src = IRB::MagicFile.open(path){|f| f.read}
 p src
 eval(src)

 $ ruby /tmp/t.rb
 #<Encoding:Windows-31J>
 /tmp/t.rb:8:in `eval': (eval):16: invalid multibyte char (UTF-8) (SyntaxError)
 (eval):16: invalid multibyte char (UTF-8)
 (eval):16: syntax error, unexpected $end, expecting keyword_end
   def_exception :UnrecognizedSwitch, '????????(%s)????????????????'
                                          ^
         from /tmp/t.rb:8:in `<main>'

cp932???????????????????????(src)??中????utf-8??????????????????????????????????
??????????utf-8???????????????eval()?????????????????????????????????

Encoding.default_internal???????????????????????????????????????????
???????????????????????????????????????????????????????込?????????????????
???????

???????????????以???????????????????????確????????????????

diff --git a/lib/irb/magic-file.rb b/lib/irb/magic-file.rb
index 8612620..339ed60 100644
--- a/lib/irb/magic-file.rb
+++ b/lib/irb/magic-file.rb
@@ -8,9 +8,10 @@ module IRB
       line = io.gets
       line = io.gets if line[0,2] == "#!"
       encoding = detect_encoding(line)
+      internal_encoding = encoding
       encoding ||= default_src_encoding
       io.rewind
-      io.set_encoding(encoding, nil)
+      io.set_encoding(encoding, internal_encoding)

       if block_given?
         begin


----------------------------------------
http://redmine.ruby-lang.org