Skip to content

Commit 73afc4b

Browse files
committed
[GR-19220] Fix IRB readline history handling when moving past bounds
PullRequest: truffleruby/3743
2 parents 8f0cc2e + d95c2e6 commit 73afc4b

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ Performance:
131131
* `Process.pid` is now cached per process like `$$` (#2882, @horakivo)
132132
* Use the system `libyaml` for `psych` to improve warmup when parsing YAML (#2089, @eregon).
133133
* Fixed repeated deoptimizations for methods building an `Array` which is growing over multiple calls at a given call site (@eregon).
134+
* Fixed errors in IRB when attempting to navigate beyond bounds in singleline mode (@rwstauner).
134135

135136
Changes:
136137

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slow:IRB ignores key sequences that would move past history in singleline mode

spec/truffle/irb/history_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../../ruby/spec_helper'
10+
11+
describe "IRB" do
12+
it "ignores key sequences that would move past history in singleline mode" do
13+
# --readline is needed otherwise Readline is not used when stdin is not a TTY.
14+
IO.popen([*ruby_exe, "-S", "irb", "-f", "--prompt=simple", "--readline", "--singleline"], "r+") do |io|
15+
io.gets.should == "Switch to inspect mode.\n"
16+
17+
io.puts "\C-n" # next-history (none)
18+
io.gets.should == ">> \n"
19+
20+
# Prove that the session is still valid.
21+
io.puts "1+1"
22+
io.gets.should == ">> 1+1\n"
23+
io.gets.should == "=> 2\n"
24+
25+
io.puts "exit"
26+
io.gets.should == ">> exit\n"
27+
end
28+
end
29+
end

src/main/java/org/truffleruby/stdlib/readline/MemoryHistory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ protected boolean matchPatterns(String patterns, String line) {
148148

149149
@Override
150150
public String current() {
151+
if (index >= size()) {
152+
return "";
153+
}
151154
return entries.get(index).line();
152155
}
153156

0 commit comments

Comments
 (0)