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

ruby-changes:26653

From: glass <ko1@a...>
Date: Sat, 5 Jan 2013 13:45:48 +0900 (JST)
Subject: [ruby-changes:26653] glass:r38704 (trunk): * string.c (rb_str_enumerate_lines): fix invalid byte sequence error

glass	2013-01-05 13:45:32 +0900 (Sat, 05 Jan 2013)

  New Revision: 38704

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38704

  Log:
    * string.c (rb_str_enumerate_lines): fix invalid byte sequence error
      when a separator is passed. The patch is from yoshidam (Yoshida
      Masato).
      [Bug #7646] [ruby-dev:46827]
    
    * test/ruby/test_string.rb: a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38703)
+++ ChangeLog	(revision 38704)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan  5 13:38:07 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* string.c (rb_str_enumerate_lines): fix invalid byte sequence error
+	  when a separator is passed. The patch is from yoshidam (Yoshida
+	  Masato).
+	  [Bug #7646] [ruby-dev:46827]
+
+	* test/ruby/test_string.rb: a test for above.
+
 Sat Jan  5 12:25:42 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* test/ruby/envutil.rb (Test::Unit::Assertions#assert_in_out_err):
Index: string.c
===================================================================
--- string.c	(revision 38703)
+++ string.c	(revision 38704)
@@ -6199,14 +6199,14 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L6199
 	if (c == newline &&
 	    (rslen <= 1 ||
 	     (pend - p >= rslen && memcmp(RSTRING_PTR(rs), p, rslen) == 0))) {
-	    p += (rslen ? rslen : n);
-	    line = rb_str_subseq(str, s - ptr, p - s);
+	    const char *pp = p + (rslen ? rslen : n);
+	    line = rb_str_subseq(str, s - ptr, pp - s);
 	    if (wantarray)
 		rb_ary_push(ary, line);
 	    else
 		rb_yield(line);
 	    str_mod_check(str, ptr, len);
-	    s = p;
+	    s = pp;
 	}
 	p += n;
     }
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 38703)
+++ test/ruby/test_string.rb	(revision 38704)
@@ -760,6 +760,11 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L760
 
     assert_equal "hello\n", S("hello\nworld").each_line.next
     assert_equal "hello\nworld", S("hello\nworld").each_line(nil).next
+
+    bug7646 = "[ruby-dev:46827]"
+    assert_nothing_raised(bug7646) do
+      "\n\u0100".each_line("\n") {}
+    end
   end
 
   def test_lines

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

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