From 3650f2460f9f58ed188ad289cfb46a1d005d2538 Mon Sep 17 00:00:00 2001 From: sanfrecce-osaka Date: Sun, 29 Dec 2024 20:00:08 +0900 Subject: [PATCH] [ruby/irb] Fix broken `history` command with -g (https://github.com/ruby/irb/pull/1057) Local variable `grep` was always nil because the regular expression parsing options contained an unnecessary `\n`. `test_history_grep` did not detect this because it only asserted what was included in the output. https://github.com/ruby/irb/commit/a282bbc0cf --- lib/irb/command/history.rb | 2 +- test/irb/test_command.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/irb/command/history.rb b/lib/irb/command/history.rb index 90f87f9102..e385c66102 100644 --- a/lib/irb/command/history.rb +++ b/lib/irb/command/history.rb @@ -14,7 +14,7 @@ module IRB def execute(arg) - if (match = arg&.match(/(-g|-G)\s+(?.+)\s*\n\z/)) + if (match = arg&.match(/(-g|-G)\s+(?.+)\s*\z/)) grep = Regexp.new(match[:grep]) end diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index 286fe04769..ec2d1f92df 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -972,6 +972,12 @@ module TestIRB puts x ... EOF + assert_not_include(out, <<~EOF) + foo + EOF + assert_not_include(out, <<~EOF) + bar + EOF assert_empty err end