File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ def load_history
89
89
def save_history
90
90
return unless self . class . const_defined? ( :HISTORY )
91
91
history = self . class ::HISTORY
92
- if num = IRB . conf [ :SAVE_HISTORY ] and ( num = num . to_i ) > 0
92
+ if num = IRB . conf [ :SAVE_HISTORY ] and ( num = num . to_i ) != 0
93
93
if history_file = IRB . conf [ :HISTORY_FILE ]
94
94
history_file = File . expand_path ( history_file )
95
95
end
@@ -110,7 +110,7 @@ def save_history
110
110
open ( history_file , "w:#{ IRB . conf [ :LC_MESSAGES ] . encoding } " , 0600 ) do |f |
111
111
hist = history . map { |l | l . split ( "\n " ) . join ( "\\ \n " ) }
112
112
begin
113
- hist = hist . last ( num ) if hist . size > num
113
+ hist = hist . last ( num ) if hist . size > num and num > 0
114
114
rescue RangeError # bignum too big to convert into `long'
115
115
# Do nothing because the bignum should be treated as inifinity
116
116
end
Original file line number Diff line number Diff line change @@ -75,6 +75,29 @@ def test_history_save_bignum
75
75
HISTORY_FILE
76
76
end
77
77
78
+ def test_history_save_minus_as_infinity
79
+ result_output , result_history_file = launch_irb_with_irbrc_and_irb_history ( <<~IRBRC , <<~IRB_HISTORY ) do |stdin |
80
+ IRB.conf[:USE_READLINE] = true
81
+ IRB.conf[:SAVE_HISTORY] = -1 # infinity
82
+ IRBRC
83
+ 1
84
+ 2
85
+ 3
86
+ 4
87
+ IRB_HISTORY
88
+ stdin . write ( "5\n exit\n " )
89
+ end
90
+
91
+ assert_equal ( <<~HISTORY_FILE , result_history_file )
92
+ 1
93
+ 2
94
+ 3
95
+ 4
96
+ 5
97
+ exit
98
+ HISTORY_FILE
99
+ end
100
+
78
101
private
79
102
80
103
def launch_irb_with_irbrc_and_irb_history ( irbrc , irb_history )
You can’t perform that action at this time.
0 commit comments