File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,12 @@ def save_history
109
109
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
- f . puts ( hist [ -num ..-1 ] || hist )
112
+ begin
113
+ hist = hist . last ( num ) if hist . size > num
114
+ rescue RangeError # bignum too big to convert into `long'
115
+ # Do nothing because the bignum should be treated as inifinity
116
+ end
117
+ f . puts ( hist )
113
118
end
114
119
end
115
120
end
Original file line number Diff line number Diff line change @@ -52,6 +52,29 @@ def test_history_save_100
52
52
HISTORY_FILE
53
53
end
54
54
55
+ def test_history_save_bignum
56
+ result_output , result_history_file = launch_irb_with_irbrc_and_irb_history ( <<~IRBRC , <<~IRB_HISTORY ) do |stdin |
57
+ IRB.conf[:USE_READLINE] = true
58
+ IRB.conf[:SAVE_HISTORY] = 10 ** 19
59
+ IRBRC
60
+ 1
61
+ 2
62
+ 3
63
+ 4
64
+ IRB_HISTORY
65
+ stdin . write ( "5\n exit\n " )
66
+ end
67
+
68
+ assert_equal ( <<~HISTORY_FILE , result_history_file )
69
+ 1
70
+ 2
71
+ 3
72
+ 4
73
+ 5
74
+ exit
75
+ HISTORY_FILE
76
+ end
77
+
55
78
private
56
79
57
80
def launch_irb_with_irbrc_and_irb_history ( irbrc , irb_history )
You can’t perform that action at this time.
0 commit comments