Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRB crashes by completion on the first line before long line #308

Closed
gotoken opened this issue Nov 15, 2021 · 1 comment · Fixed by ruby/reline#388
Closed

IRB crashes by completion on the first line before long line #308

gotoken opened this issue Nov 15, 2021 · 1 comment · Fixed by ruby/reline#388

Comments

@gotoken
Copy link
Member

gotoken commented Nov 15, 2021

Description

  1. Start irb and paste this:
0+
12345678901234
  1. you get
irb(main):001:0* 0+
irb(main):002:0> 12345678901234
  1. hit the Up arrow key and then move cursor to the end of first line of previous input. Now type ra looks like as
irb(main):001:0* 0+ ra
irb(main):002:0> 12345678901234
  1. irb crashes immediately
irb(main):001:0* 0+ ra
irb(main):002:0> 123remov/home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:649:in `*': negative argument (ArgumentError)o?
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:649:in `padding_space_with_escape_sequences'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:861:in `block in reset_dialog'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:855:in `times'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:855:in `reset_dialog'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:732:in `render_each_dialog'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:644:in `block in render_dialog'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:643:in `each'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:643:in `render_dialog'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline/line_editor.rb:507:in `rerender'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:325:in `block (3 levels) in inner_readline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:323:in `each'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:323:in `block (2 levels) in inner_readline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:393:in `block in read_io'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:363:in `loop'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:363:in `read_io'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:321:in `block in inner_readline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:319:in `loop'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:319:in `inner_readline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/reline.rb:249:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/forwardable.rb:238:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/forwardable.rb:238:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/input-method.rb:416:in `gets'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:538:in `block (2 levels) in eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:769:in `signal_status'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:537:in `block in eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:282:in `lex'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:251:in `block (2 levels) in ach_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:248:in `loop'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:248:in `block in each_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:247:in `catch'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:247:in `each_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:556:in `eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:490:in `block in run'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:489:in `catch'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:489:in `run'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:418:in `start'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/gems/3.1.0/gems/irb-1.3.8.pre.11/exe/irb:11:in `<top (required)>'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/bin/irb:25:in `load'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/bin/irb:25:in `<main>'
$ 
  1. If input is shorter, the crash is not reproduced
0+
1234567890123

Result of irb_info

irb(main):001:0> irb_info
=>
Ruby version: 3.1.0
IRB version: irb 1.3.8.pre.11 (2021-10-09)
InputMethod: ReidlineInputMethod with Reline 0.2.8.pre.11
RUBY_PLATFORM: x86_64-linux
LANG env: en_US.UTF-8

ima1zumi added a commit to ima1zumi/reline that referenced this issue Nov 17, 2021
@gotoken
Copy link
Member Author

gotoken commented Nov 17, 2021

ima1zumi/reline@161ab4f

Look good to me. Thanks. I've tried that with

% git status
HEAD detached at 161ab4f
nothing to commit, working tree clean
% ruby -I lib -r ./lib/reline -r ./lib/reline/line_editor.rb -S irb

But another input kills irb again.

irb(main):001:1* def blur
irb(main):002:1*   #
irb(main):003:0> end
=> :blur

And hit up arrow key to start editing, then type ra at the comment line:

irb(main):004:1* def blur
irb(main):005:1*   # ra
irb(main):006:0> end remov/home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:649:in `padding_space_with_escape_sequences': undefined method `-' for "\\e[32m\\e[0m":String (NoMethodError)
                     respond_to?
    str + (' ' * (width - calculate_width(str, true)))
                        ^
Did you mean?  -@
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:866:in `block in reset_dialog'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:855:in `times'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:855:in `reset_dialog'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:732:in `render_each_dialog'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:644:in `block in render_dialog'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:643:in `each'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:643:in `render_dialog'
        from /home/ruby/work/ima1zumi/reline/lib/reline/line_editor.rb:507:in `rerender'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:325:in `block (3 levels) in inner_readline'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:323:in `each'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:323:in `block (2 levels) in inner_readline'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:393:in `block in read_io'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:363:in `loop'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:363:in `read_io'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:321:in `block in inner_readline'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:319:in `loop'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:319:in `inner_readline'
        from /home/ruby/work/ima1zumi/reline/lib/reline.rb:249:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/forwardable.rb:238:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/forwardable.rb:238:in `readmultiline'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/input-method.rb:416:in `gets'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:538:in `block (2 levels) in eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:769:in `signal_status'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:537:in `block in eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:282:in `lex'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:251:in `block (2 levels) in each_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:248:in `loop'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:248:in `block in each_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:247:in `catch'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb/ruby-lex.rb:247:in `each_top_level_statement'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:556:in `eval_input'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:490:in `block in run'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:489:in `catch'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:489:in `run'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/3.1.0/irb.rb:418:in `start'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/lib/ruby/gems/3.1.0/gems/irb-1.3.8.pre.11/exe/irb:11:in `<top (required)>'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/bin/irb:25:in `load'
        from /home/ruby/.rbenv/versions/3.1.0-preview1/bin/irb:25:in `<main>'
%

ima1zumi added a commit to ima1zumi/reline that referenced this issue Nov 19, 2021
ima1zumi added a commit to ima1zumi/reline that referenced this issue Nov 20, 2021
fix ruby/irb#308

This bug occurred when `dialog.width - calculate_width(s, true)` was negative.

When `dialog.width` is shorter than `old_dialog.width`, it calculates how much padding it has to do. However, there are cases where `s` is longer than `dialog.width`, as in the issue. In that case, `padding_space_with_escape_sequences` will crash.

Here, `old_dialog.width` is longer than `dialog.width`, so I changed the padding width to `old_dialog.width - dialog.width`.
matzbot pushed a commit to ruby/ruby that referenced this issue Nov 21, 2021
fix ruby/irb#308

This bug occurred when `dialog.width - calculate_width(s, true)` was negative.

When `dialog.width` is shorter than `old_dialog.width`, it calculates how much padding it has to do. However, there are cases where `s` is longer than `dialog.width`, as in the issue. In that case, `padding_space_with_escape_sequences` will crash.

Here, `old_dialog.width` is longer than `dialog.width`, so I changed the padding width to `old_dialog.width - dialog.width`.

ruby/reline@c581c31e0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant