[前][次][番号順一覧][スレッド一覧]

ruby-changes:60506

From: aycabta <ko1@a...>
Date: Thu, 26 Mar 2020 17:44:29 +0900 (JST)
Subject: [ruby-changes:60506] f245fb1ab8 (master): [ruby/reline] Work with wrong $/ value correctly

https://git.ruby-lang.org/ruby.git/commit/?id=f245fb1ab8

From f245fb1ab8d893a89c8749a703efea0b16353028 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sun, 23 Feb 2020 12:35:24 +0900
Subject: [ruby/reline] Work with wrong $/ value correctly

https://github.com/ruby/reline/commit/962ebf5a1b

diff --git a/lib/reline.rb b/lib/reline.rb
index 3303fb4..2708cd9 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -175,7 +175,7 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L175
 
       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
 
@@ -188,8 +188,8 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L188
 
       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?
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 478d1d7..095a7b5 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -543,7 +543,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L543
     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
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index 7e97caa..c16212c 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -1896,6 +1896,15 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_emacs.rb#L1896
     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')
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]