mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Suppress crash when bignum is set to SAVE_HISTORY
5044eb2730
This commit is contained in:
parent
1359da6ec0
commit
ef498a016b
2 changed files with 29 additions and 1 deletions
|
@ -109,7 +109,12 @@ module IRB
|
||||||
|
|
||||||
open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
|
open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
|
||||||
hist = history.map{ |l| l.split("\n").join("\\\n") }
|
hist = history.map{ |l| l.split("\n").join("\\\n") }
|
||||||
f.puts(hist[-num..-1] || hist)
|
begin
|
||||||
|
hist = hist.last(num) if hist.size > num
|
||||||
|
rescue RangeError # bignum too big to convert into `long'
|
||||||
|
# Do nothing because the bignum should be treated as inifinity
|
||||||
|
end
|
||||||
|
f.puts(hist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,6 +52,29 @@ module TestIRB
|
||||||
HISTORY_FILE
|
HISTORY_FILE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_history_save_bignum
|
||||||
|
result_output, result_history_file = launch_irb_with_irbrc_and_irb_history(<<~IRBRC, <<~IRB_HISTORY) do |stdin|
|
||||||
|
IRB.conf[:USE_READLINE] = true
|
||||||
|
IRB.conf[:SAVE_HISTORY] = 10 ** 19
|
||||||
|
IRBRC
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
IRB_HISTORY
|
||||||
|
stdin.write("5\nexit\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(<<~HISTORY_FILE, result_history_file)
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
exit
|
||||||
|
HISTORY_FILE
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history)
|
def launch_irb_with_irbrc_and_irb_history(irbrc, irb_history)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue