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

ruby-changes:28361

From: knu <ko1@a...>
Date: Tue, 23 Apr 2013 09:52:28 +0900 (JST)
Subject: [ruby-changes:28361] knu:r40413 (trunk): * string.c (rb_str_inspect): NUL should not be represented as

knu	2013-04-23 09:52:17 +0900 (Tue, 23 Apr 2013)

  New Revision: 40413

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

  Log:
    * string.c (rb_str_inspect): NUL should not be represented as
      "\0" when octal digits may follow.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40412)
+++ ChangeLog	(revision 40413)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Apr 23 09:51:26 2013  Akinori MUSHA  <knu@i...>
+
+	* string.c (rb_str_inspect): NUL should not be represented as
+	  "\0" when octal digits may follow.
+
 Mon Apr 22 22:54:00 2013  Charlie Somerville  <charlie@c...>
 
 	* insns.def (opt_mod): Use % operator if both operands are positive for
Index: string.c
===================================================================
--- string.c	(revision 40412)
+++ string.c	(revision 40413)
@@ -4572,7 +4572,11 @@ rb_str_inspect(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L4572
 	    }
 	}
 	switch (c) {
-	  case '\0': cc = '0'; break;
+	  case '\0':
+	    if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
+	    str_buf_cat(result, "\\000", 4);
+	    prev = p;
+	    continue;
 	  case '\n': cc = 'n'; break;
 	  case '\r': cc = 'r'; break;
 	  case '\t': cc = 't'; break;
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 40412)
+++ test/ruby/test_string.rb	(revision 40413)
@@ -1985,6 +1985,12 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1985
     assert_instance_of(String, s.to_s)
   end
 
+  def test_inspect_nul
+    s = "\0" + "12"
+    assert_not_equal '"\\012"', eval(s.inspect)
+    assert_equal s, eval(s.inspect)
+  end
+
   def test_partition
     assert_equal(%w(he l lo), "hello".partition(/l/))
     assert_equal(%w(he l lo), "hello".partition("l"))

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

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