[ruby/irb] Scrub past history input before split
(https://github.com/ruby/irb/pull/795) * Scrub past history input before split * Don't rewrite ENV["LANG"] https://github.com/ruby/irb/commit/0f344f66d9
This commit is contained in:
parent
73440e1ef2
commit
ef466ac931
@ -60,7 +60,7 @@ module IRB
|
|||||||
end
|
end
|
||||||
|
|
||||||
File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
|
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
|
unless append_history
|
||||||
begin
|
begin
|
||||||
hist = hist.last(num) if hist.size > num and num > 0
|
hist = hist.last(num) if hist.size > num and num > 0
|
||||||
|
@ -148,6 +148,23 @@ module TestIRB
|
|||||||
ENV["IRBRC"] = backup_irbrc
|
ENV["IRBRC"] = backup_irbrc
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def history_concurrent_use_for_input_method(input_method)
|
def history_concurrent_use_for_input_method(input_method)
|
||||||
@ -179,11 +196,11 @@ module TestIRB
|
|||||||
end
|
end
|
||||||
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_verbose, $VERBOSE = $VERBOSE, nil
|
||||||
backup_home = ENV["HOME"]
|
backup_home = ENV["HOME"]
|
||||||
backup_xdg_config_home = ENV.delete("XDG_CONFIG_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
|
actual_history = nil
|
||||||
Dir.mktmpdir("test_irb_history_") do |tmpdir|
|
Dir.mktmpdir("test_irb_history_") do |tmpdir|
|
||||||
ENV["HOME"] = tmpdir
|
ENV["HOME"] = tmpdir
|
||||||
|
Loading…
x
Reference in New Issue
Block a user