Issue #4281 has been updated by Yui NARUSE.

Category changed from ext to lib
Status changed from Open to Assigned
Assignee set to Keiju Ishitsuka

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

Author: Narihiro Nakamura
Status: Assigned
Priority: Normal
Assignee: Keiju Ishitsuka
Category: lib
Target version: 1.9.2
ruby -v: ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]


=begin
 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
=end



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