From f36c61d27fcdc47d4aa34e8a3b52590aac08bb69 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 1 Feb 2024 16:19:03 +0000 Subject: [ruby/irb] Reset history counter even when @loaded_history_lines is not defined (https://github.com/ruby/irb/pull/853) The issue (https://github.com/ruby/debug/issues/1064) is caused by a combination of factors: 1. When user starts an IRB session without a history file, the `@loaded_history_lines` ivar is not defined. 2. If the user then starts the `irb:rdbg` session, the history counter is not set, because the `@loaded_history_lines` is not defined. 3. Because `irb:rdbg` saves the history before passing Ruby expression to the debugger, it saves the history with duplicated lines. The number grows in exponential order. 4. When the user exits the `irb:rdbg` session, the history file could be bloated with duplicated lines. This commit fixes the issue by resetting the history counter even when `@loaded_history_lines` is not defined. https://github.com/ruby/irb/commit/4afc98c258 --- lib/irb/history.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/irb/history.rb b/lib/irb/history.rb index 50fe1ce229..90aa9f0bcf 100644 --- a/lib/irb/history.rb +++ b/lib/irb/history.rb @@ -5,7 +5,7 @@ module IRB end def reset_history_counter - @loaded_history_lines = self.class::HISTORY.size if defined? @loaded_history_lines + @loaded_history_lines = self.class::HISTORY.size end def load_history -- cgit v1.2.3