From d27fa87418bcec8fff909f75a547a7c5e6dc83e5 Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 25 Apr 2020 01:45:03 +0900 Subject: [PATCH] [ruby/reline] New items to history are dropped if history_size is zero https://github.com/ruby/reline/commit/9bdbed9cbc --- lib/reline/history.rb | 4 ++++ test/reline/test_history.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/reline/history.rb b/lib/reline/history.rb index d95f1cebc3..2e6a12ecf3 100644 --- a/lib/reline/history.rb +++ b/lib/reline/history.rb @@ -29,6 +29,8 @@ class Reline::History < Array end def push(*val) + # If history_size is zero, all histories are dropped. + return self if @config.history_size.zero? diff = size + val.size - @config.history_size if diff > 0 if diff <= size @@ -43,6 +45,8 @@ class Reline::History < Array end def <<(val) + # If history_size is zero, all histories are dropped. + return self if @config.history_size.zero? shift if size + 1 > @config.history_size super(String.new(val, encoding: Reline.encoding_system_needs)) end diff --git a/test/reline/test_history.rb b/test/reline/test_history.rb index 189f2db86d..0cb148d112 100644 --- a/test/reline/test_history.rb +++ b/test/reline/test_history.rb @@ -242,6 +242,16 @@ class Reline::History::Test < Reline::TestCase end end + def test_history_size_zero + history = history_new(history_size: 0) + assert_equal 0, history.size + history << 'aa' + history << 'bb' + assert_equal 0, history.size + history.push(*%w{aa bb cc}) + assert_equal 0, history.size + end + private def history_new(history_size: 10)