Skip to content

Commit 9bdbed9

Browse files
committed
New items to history are dropped if history_size is zero
1 parent b349c50 commit 9bdbed9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/reline/history.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def concat(*val)
2929
end
3030

3131
def push(*val)
32+
# If history_size is zero, all histories are dropped.
33+
return self if @config.history_size.zero?
3234
diff = size + val.size - @config.history_size
3335
if diff > 0
3436
if diff <= size
@@ -43,6 +45,8 @@ def push(*val)
4345
end
4446

4547
def <<(val)
48+
# If history_size is zero, all histories are dropped.
49+
return self if @config.history_size.zero?
4650
shift if size + 1 > @config.history_size
4751
super(String.new(val, encoding: Reline.encoding_system_needs))
4852
end

test/reline/test_history.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ def test_delete_at__out_of_range
242242
end
243243
end
244244

245+
def test_history_size_zero
246+
history = history_new(history_size: 0)
247+
assert_equal 0, history.size
248+
history << 'aa'
249+
history << 'bb'
250+
assert_equal 0, history.size
251+
history.push(*%w{aa bb cc})
252+
assert_equal 0, history.size
253+
end
254+
245255
private
246256

247257
def history_new(history_size: 10)

0 commit comments

Comments
 (0)