Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrub past history input before split #795

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
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
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
21 changes: 19 additions & 2 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ def test_history_concurrent_use_not_present
ENV["IRBRC"] = backup_irbrc
end

def test_history_different_encodings
backup_default_external = Encoding.default_external
IRB.conf[:SAVE_HISTORY] = 2
Encoding.default_external = Encoding::US_ASCII
locale = IRB::Locale.new("C")
assert_history(<<~EXPECTED_HISTORY.encode(Encoding::US_ASCII), <<~INITIAL_HISTORY.encode(Encoding::UTF_8), <<~INPUT, locale: locale)
????
exit
EXPECTED_HISTORY
πŸ˜€
INITIAL_HISTORY
exit
INPUT
ensure
Encoding.default_external = backup_default_external
end

private

def history_concurrent_use_for_input_method(input_method)
Expand Down Expand Up @@ -179,11 +196,11 @@ def history_concurrent_use_for_input_method(input_method)
end
end

def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory)
def assert_history(expected_history, initial_irb_history, input, input_method = TestInputMethodWithRelineHistory, locale: IRB::Locale.new)
backup_verbose, $VERBOSE = $VERBOSE, nil
backup_home = ENV["HOME"]
backup_xdg_config_home = ENV.delete("XDG_CONFIG_HOME")
IRB.conf[:LC_MESSAGES] = IRB::Locale.new
IRB.conf[:LC_MESSAGES] = locale
actual_history = nil
Dir.mktmpdir("test_irb_history_") do |tmpdir|
ENV["HOME"] = tmpdir
Expand Down
Loading