Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/debug/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def history_file
def read_history_file
if history && File.exist?(path = history_file)
f = (['', 'DAI-', 'CHU-', 'SHO-'].map{|e| e+'KICHI'}+['KYO']).sample
["#{FH}#{f}".dup] + File.readlines(path)
# Read history file and scrub invalid characters to prevent encoding errors
lines = File.readlines(path).map(&:scrub)
["#{FH}#{f}".dup] + lines
else
[]
end
Expand All @@ -193,8 +195,10 @@ def deactivate
orig_records = read_history_file
open(history_file, 'w'){|f|
(orig_records + added_records).last(max).each{|line|
if !line.start_with?(FH) && !line.strip.empty?
f.puts line.strip
# Use scrub to handle encoding issues gracefully
scrubbed_line = line.scrub.strip
if !line.start_with?(FH) && !scrubbed_line.empty?
f.puts scrubbed_line
end
}
}
Expand All @@ -204,6 +208,8 @@ def deactivate

def load_history
read_history_file.each{|line|
# Use scrub to handle encoding issues gracefully, then strip
line.scrub!
line.strip!
history << line unless line.empty?
} if history.empty?
Expand Down
Loading