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

ruby-changes:45015

From: nobu <ko1@a...>
Date: Fri, 16 Dec 2016 10:12:16 +0900 (JST)
Subject: [ruby-changes:45015] nobu:r57088 (trunk): fix chomping newline only line

nobu	2016-12-16 10:12:09 +0900 (Fri, 16 Dec 2016)

  New Revision: 57088

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57088

  Log:
    fix chomping newline only line
    
    * string.c (chomp_newline): fix chomping newline only line.
      rb_enc_prev_char return NULL if no previous character and must
      not call rb_enc_ascget on it.  a patch by Ary Borenszweig
      <asterite AT gmail.com> at [ruby-core:78666].  [Bug #13037]

  Modified files:
    trunk/string.c
    trunk/test/ruby/test_string.rb
Index: string.c
===================================================================
--- string.c	(revision 57087)
+++ string.c	(revision 57088)
@@ -7409,7 +7409,7 @@ chomp_newline(const char *p, const char https://github.com/ruby/ruby/blob/trunk/string.c#L7409
     if (rb_enc_is_newline(prev, e, enc)) {
 	e = prev;
 	prev = rb_enc_prev_char(p, e, e, enc);
-	if (rb_enc_ascget(prev, e, NULL, enc) == '\r')
+	if (prev && rb_enc_ascget(prev, e, NULL, enc) == '\r')
 	    e = prev;
     }
     return e;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 57087)
+++ test/ruby/test_string.rb	(revision 57088)
@@ -843,6 +843,18 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L843
 
     assert_equal "hello", S("hello\nworld").each_line(chomp: true).next
     assert_equal "hello\nworld", S("hello\nworld").each_line(nil, chomp: true).next
+
+    res = []
+    S("").each_line(chomp: true) {|x| res << x}
+    assert_equal([], res)
+
+    res = []
+    S("\n").each_line(chomp: true) {|x| res << x}
+    assert_equal([S("")], res)
+
+    res = []
+    S("\r\n").each_line(chomp: true) {|x| res << x}
+    assert_equal([S("")], res)
   end
 
   def test_lines

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

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