Skip to content

Commit

Permalink
Fix broken history command with -g (#1057)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sanfrecce-osaka authored Dec 29, 2024
1 parent d2b73cb commit a282bbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb/command/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class History < Base

def execute(arg)

if (match = arg&.match(/(-g|-G)\s+(?<grep>.+)\s*\n\z/))
if (match = arg&.match(/(-g|-G)\s+(?<grep>.+)\s*\z/))
grep = Regexp.new(match[:grep])
end

Expand Down
6 changes: 6 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,12 @@ def test_history_grep
puts x
...
EOF
assert_not_include(out, <<~EOF)
foo
EOF
assert_not_include(out, <<~EOF)
bar
EOF
assert_empty err
end

Expand Down

0 comments on commit a282bbc

Please sign in to comment.