Skip to content

Commit 3650f24

Browse files
sanfrecce-osakamatzbot
authored andcommitted
[ruby/irb] Fix broken history command with -g
(ruby/irb#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. ruby/irb@a282bbc0cf
1 parent a33c944 commit 3650f24

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/irb/command/history.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class History < Base
1414

1515
def execute(arg)
1616

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

test/irb/test_command.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,12 @@ def test_history_grep
972972
puts x
973973
...
974974
EOF
975+
assert_not_include(out, <<~EOF)
976+
foo
977+
EOF
978+
assert_not_include(out, <<~EOF)
979+
bar
980+
EOF
975981
assert_empty err
976982
end
977983

0 commit comments

Comments
 (0)