8000 Work with wrong $/ value correctly · ruby/reline@962ebf5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 962ebf5

Browse files
committed
Work with wrong $/ value correctly
1 parent 97ac70e commit 962ebf5

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/reline.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
175175

176176
whole_buffer = line_editor.whole_buffer.dup
177177
whole_buffer.taint if RUBY_VERSION < '2.7'
178-
if add_hist and whole_buffer and whole_buffer.chomp.size > 0
178+
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
179179
Reline::HISTORY << whole_buffer
180180
end
181181

@@ -188,8 +188,8 @@ def readline(prompt = '', add_hist = false)
188188

189189
line = line_editor.line.dup
190190
line.taint if RUBY_VERSION < '2.7'
191-
if add_hist and line and line.chomp.size > 0
192-
Reline::HISTORY << line.chomp
191+
if add_hist and line and line.chomp("\n").size > 0
192+
Reline::HISTORY << line.chomp("\n")
193193
end
194194

195195
line_editor.reset_line if line_editor.line.nil?

lib/reline/line_editor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def rerender
543543
return before if before.nil? || before.empty?
544544

545545
if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: finished?)
546-
after.lines(chomp: true)
546+
after.lines("\n", chomp: true)
547547
else
548548
before
549549
end

test/reline/test_key_actor_emacs.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,15 @@ def test_em_set_mark_and_em_exchange_mark
18961896
assert_equal([0, 0], @line_editor.instance_variable_get(:@mark_pointer))
18971897
end
18981898

1899+
def test_modify_lines_with_wrong_rs
1900+
original_global_slash = $/
1901+
$/ = 'b'
1902+
@line_editor.output_modifier_proc = proc { |output| Reline::Unicode.escape_for_print(output) }
1903+
input_keys("abcdef\n")
1904+
assert_equal(['abcdef'], @line_editor.__send__(:modify_lines, @line_editor.whole_lines))
1905+
$/ = original_global_slash
1906+
end
1907+
18991908
=begin # TODO: move KeyStroke instance from Reline to LineEditor
19001909
def test_key_delete
19011910
input_keys('ab')

0 commit comments

Comments
 (0)
0