Skip to content

Commit

Permalink
Fix crash on TAB under ruby 2.7 (#657)
Browse files Browse the repository at this point in the history
When IRB from ruby 2.7 is loaded, it installs a Readline completion proc
that assumes IRB is running (and crashes otherwise). Workaround this by
clearing the Readline completion when using it directly.
  • Loading branch information
terceiro committed Apr 17, 2020
1 parent a3da24e commit 7c4aad4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

* [#657](https://github.com/deivid-rodriguez/byebug/pull/657): crash when hitting \<TAB\> due to IRB completion mechanism included in the default ruby 2.7 version of the `irb` gem ([@terceiro]).

## [11.1.1] - 2020-01-24

### Fixed
Expand Down Expand Up @@ -911,6 +915,7 @@
[@sethk]: https://github.com/sethk
[@shuky19]: https://github.com/shuky19
[@tacnoman]: https://github.com/tacnoman
[@terceiro]: https://github.com/terceiro
[@tzmfreedom]: https://github.com/tzmfreedom
[@wallace]: https://github.com/wallace
[@windwiny]: https://github.com/windwiny
Expand Down
21 changes: 20 additions & 1 deletion lib/byebug/interfaces/local_interface.rb
Expand Up @@ -21,7 +21,7 @@ def initialize
# @param prompt Prompt to be displayed.
#
def readline(prompt)
with_repl_like_sigint { Readline.readline(prompt) || EOF_ALIAS }
with_repl_like_sigint { without_readline_completion { Readline.readline(prompt) || EOF_ALIAS } }
end

#
Expand All @@ -40,5 +40,24 @@ def with_repl_like_sigint
ensure
trap("INT", orig_handler)
end

#
# Disable any Readline completion procs.
#
# Other gems, for example, IRB could've installed completion procs that are
# dependent on them being loaded. Disable those while byebug is the REPL
# making use of Readline.
#
def without_readline_completion
orig_completion = Readline.completion_proc
return yield unless orig_completion

begin
Readline.completion_proc = nil
yield
ensure
Readline.completion_proc = orig_completion
end
end
end
end
9 changes: 9 additions & 0 deletions test/runner_against_valid_program_test.rb
Expand Up @@ -118,6 +118,15 @@ def test_run_with_debug_flag
assert_match(/Debug flag is true/, stdout)
end

def test_run_and_press_tab_doesnt_make_byebug_crash
stdout = run_byebug(
example_path,
input: "\tputs 'Reached here'"
)

assert_match(/Reached here/, stdout)
end

def test_run_stops_at_the_first_line_by_default
stdout = run_byebug(example_path)

Expand Down

0 comments on commit 7c4aad4

Please sign in to comment.