From 7c4aad4118bc713f32c997c191839dac495614f3 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 17 Apr 2020 13:51:55 -0300 Subject: [PATCH] Fix crash on TAB under ruby 2.7 (#657) 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. --- CHANGELOG.md | 5 +++++ lib/byebug/interfaces/local_interface.rb | 21 ++++++++++++++++++++- test/runner_against_valid_program_test.rb | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef1d94e7b..e5889dc56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +* [#657](https://github.com/deivid-rodriguez/byebug/pull/657): crash when hitting \ 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 @@ -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 diff --git a/lib/byebug/interfaces/local_interface.rb b/lib/byebug/interfaces/local_interface.rb index 65b7d67c8..9996e3a4b 100644 --- a/lib/byebug/interfaces/local_interface.rb +++ b/lib/byebug/interfaces/local_interface.rb @@ -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 # @@ -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 diff --git a/test/runner_against_valid_program_test.rb b/test/runner_against_valid_program_test.rb index 9555ccfba..25b65454e 100644 --- a/test/runner_against_valid_program_test.rb +++ b/test/runner_against_valid_program_test.rb @@ -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)