Skip to content

Commit

Permalink
Work with wrong $/ value correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Feb 23, 2020
1 parent 97ac70e commit 962ebf5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)

whole_buffer = line_editor.whole_buffer.dup
whole_buffer.taint if RUBY_VERSION < '2.7'
if add_hist and whole_buffer and whole_buffer.chomp.size > 0
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
Reline::HISTORY << whole_buffer
end

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

line = line_editor.line.dup
line.taint if RUBY_VERSION < '2.7'
if add_hist and line and line.chomp.size > 0
Reline::HISTORY << line.chomp
if add_hist and line and line.chomp("\n").size > 0
Reline::HISTORY << line.chomp("\n")
end

line_editor.reset_line if line_editor.line.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def rerender
return before if before.nil? || before.empty?

if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: finished?)
after.lines(chomp: true)
after.lines("\n", chomp: true)
else
before
end
Expand Down
9 changes: 9 additions & 0 deletions test/reline/test_key_actor_emacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,15 @@ def test_em_set_mark_and_em_exchange_mark
assert_equal([0, 0], @line_editor.instance_variable_get(:@mark_pointer))
end

def test_modify_lines_with_wrong_rs
original_global_slash = $/
$/ = 'b'
@line_editor.output_modifier_proc = proc { |output| Reline::Unicode.escape_for_print(output) }
input_keys("abcdef\n")
assert_equal(['abcdef'], @line_editor.__send__(:modify_lines, @line_editor.whole_lines))
$/ = original_global_slash
end

=begin # TODO: move KeyStroke instance from Reline to LineEditor
def test_key_delete
input_keys('ab')
Expand Down

0 comments on commit 962ebf5

Please sign in to comment.