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

ruby-changes:13724

From: nobu <ko1@a...>
Date: Tue, 27 Oct 2009 22:06:02 +0900 (JST)
Subject: [ruby-changes:13724] Ruby:r25515 (ruby_1_8): * string.c (rb_str_inspect): get rid of adding garbage to short

nobu	2009-10-27 22:05:48 +0900 (Tue, 27 Oct 2009)

  New Revision: 25515

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

  Log:
    * string.c (rb_str_inspect): get rid of adding garbage to short
      UTF-8 string.  [ruby-dev:39550]

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

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 25514)
+++ ruby_1_8/ChangeLog	(revision 25515)
@@ -1,3 +1,8 @@
+Tue Oct 27 22:05:46 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_inspect): get rid of adding garbage to shor
+	  UTF-8 string.  [ruby-dev:39550]
+
 Tue Oct 27 21:20:35 2009  Hidetoshi NAGAI  <nagai@a...>
 
 	* ext/tk/lib/tk/variable.rb: add TkVariable#+@ and -@ method.
Index: ruby_1_8/string.c
===================================================================
--- ruby_1_8/string.c	(revision 25514)
+++ ruby_1_8/string.c	(revision 25515)
@@ -2718,8 +2718,8 @@
     p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
     while (p < pend) {
 	char c = *p++;
-	if (ismbchar(c) && p < pend) {
-	    int len = mbclen(c);
+	int len;
+	if (ismbchar(c) && p + (len = mbclen(c)) <= pend) {
 	    rb_str_buf_cat(result, p - 1, len);
 	    p += len - 1;
 	}
Index: ruby_1_8/test/ruby/test_string.rb
===================================================================
--- ruby_1_8/test/ruby/test_string.rb	(revision 25514)
+++ ruby_1_8/test/ruby/test_string.rb	(revision 25515)
@@ -140,4 +140,17 @@
   ensure
     $KCODE = original_kcode
   end
+
+  def test_inspect
+    original_kcode = $KCODE
+
+    $KCODE = 'n'
+    assert_equal('"\343\201\202"', "\xe3\x81\x82".inspect)
+
+    $KCODE = 'u'
+    assert_equal("\"\xe3\x81\x82\"", "\xe3\x81\x82".inspect)
+    assert_no_match(/\0/, "\xe3\x81".inspect, '[ruby-dev:39550]')
+  ensure
+    $KCODE = original_kcode
+  end
 end

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

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