Bug #18350
closedString with foreign character results in: TypeError (nil can't be coerced into Integer)
Description
2.7.2 :001 > s = "Púrpura"
Traceback (most recent call last):
7: from /Users/xxx/.rvm/rubies/ruby-2.7.2/bin/irb:23:in `<main>'
6: from /Users/xxx/.rvm/rubies/ruby-2.7.2/bin/irb:23:in `load'
5: from /Users/xxx/.rvm/rubies/ruby-2.7.2/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
4: from /Users/xxx/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/reline/unicode.rb:99:in `calculate_width'
3: from /Users/xxx/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/reline/unicode.rb:99:in `scan'
2: from /Users/xxx/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/reline/unicode.rb:108:in `block in calculate_width'
1: from /Users/xxx/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/reline/unicode.rb:108:in `+'
TypeError (nil can't be coerced into Integer)
2.7.2 :002 >
Ruby 2.6.3 does not have this problem:
2.6.3 :001 > s = "Púrpura"
=> "Púrpura"
2.6.3 :002 >
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
I cannot reproduce this on Windows using the default 437 code page (using Ruby 2.7.0) or on OpenBSD (using Ruby 2.7.4):
C:\Ruby27-x64\bin>chcp
Active code page: 437
C:\Ruby27-x64\bin>set RUBYOPT=-Ku
C:\Ruby27-x64\bin>irb
irb(main):001:0> s = "Púrpura"
irb(main):002:0> s
=> "Púrpura"
irb(main):003:0> RUBY_VERSION
=> "2.7.0"
$ RUBYOPT=-Ku irb27
irb(main):001:0> s = "Púrpura"
=> "Púrpura"
irb(main):002:0> RUBY_VERSION
=> "2.7.4"
When I try it on Windows with the 65001 (UTF-8) code page, the entire command prompt window containing irb closes (not just the ruby process). I also tried with Ruby 3.0 and got the same result. I can paste the s = "Púrpura"
text directly into the command prompt outside of irb, so it doesn't appear to be purely a Windows command prompt issue.
You appear to be running on Mac, so the situation must be different there. Can you reproduce this issue with Ruby 3.0?
Updated by diadbrown (Dave Brown) over 2 years ago
@jeremyevans0 (Jeremy Evans) I don't have 3.0.0 here, and since my Mac is somewhat old I can't get it to install. Maybe someone else on Mac with 3.0.0 can try?
jeremyevans0 (Jeremy Evans) wrote in #note-1:
I cannot reproduce this on Windows using the default 437 code page (using Ruby 2.7.0) or on OpenBSD (using Ruby 2.7.4):
C:\Ruby27-x64\bin>chcp Active code page: 437 C:\Ruby27-x64\bin>set RUBYOPT=-Ku C:\Ruby27-x64\bin>irb irb(main):001:0> s = "Púrpura" irb(main):002:0> s => "Púrpura" irb(main):003:0> RUBY_VERSION => "2.7.0"
$ RUBYOPT=-Ku irb27 irb(main):001:0> s = "Púrpura" => "Púrpura" irb(main):002:0> RUBY_VERSION => "2.7.4"
When I try it on Windows with the 65001 (UTF-8) code page, the entire command prompt window containing irb closes (not just the ruby process). I also tried with Ruby 3.0 and got the same result. I can paste the
s = "Púrpura"
text directly into the command prompt outside of irb, so it doesn't appear to be purely a Windows command prompt issue.You appear to be running on Mac, so the situation must be different there. Can you reproduce this issue with Ruby 3.0?
Updated by diadbrown (Dave Brown) over 2 years ago
@jeremyevans0 (Jeremy Evans) I found the issue: https://github.com/ruby/irb/issues/261
This fixed it.
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
- Status changed from Open to Closed