Skip to content

Commit

Permalink
Scrub past history input before split
Browse files Browse the repository at this point in the history
  • Loading branch information
hogelog committed Dec 1, 2023
1 parent 4fedce9 commit c2c3bb7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def save_history
end

File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
hist = history.map{ |l| l.split("\n").join("\\\n") }
hist = history.map{ |l| l.scrub.split("\n").join("\\\n") }
unless append_history
begin
hist = hist.last(num) if hist.size > num and num > 0
Expand Down
19 changes: 19 additions & 0 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ def test_history_concurrent_use_not_present
ENV["IRBRC"] = backup_irbrc
end

def test_history_different_encodings
backup_default_external = Encoding.default_external
backup_lang = ENV["LANG"]
IRB.conf[:SAVE_HISTORY] = 2
ENV["LANG"] = "C"
Encoding.default_external = Encoding::US_ASCII
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT)
????
exit
EXPECTED_HISTORY
😀
INITIAL_HISTORY
exit
INPUT
ensure
ENV["LANG"] = backup_lang
Encoding.default_external = backup_default_external
end

private

def history_concurrent_use_for_input_method(input_method)
Expand Down

0 comments on commit c2c3bb7

Please sign in to comment.