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

ruby-changes:18159

From: naruse <ko1@a...>
Date: Sun, 12 Dec 2010 04:03:32 +0900 (JST)
Subject: [ruby-changes:18159] Ruby:r30180 (trunk): * string.c (rb_str_inspect): fix: extra back slash is added when

naruse	2010-12-12 04:03:26 +0900 (Sun, 12 Dec 2010)

  New Revision: 30180

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

  Log:
    * string.c (rb_str_inspect): fix: extra back slash is added when
      the string is dummy encoding and includes \x22 or \x5C.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30179)
+++ ChangeLog	(revision 30180)
@@ -1,3 +1,8 @@
+Sun Dec 12 04:01:58 2010  NARUSE, Yui  <naruse@r...>
+
+	* string.c (rb_str_inspect): fix: extra back slash is added when
+	  the string is dummy encoding and includes \x22 or \x5C.
+
 Sun Dec 12 02:42:24 2010  Aaron Patterson <aaron@t...>
 
 	* ext/openssl/ossl_asn1.c: indefinite length BER to DER encoding is
Index: string.c
===================================================================
--- string.c	(revision 30179)
+++ string.c	(revision 30180)
@@ -4251,12 +4251,13 @@
         n = MBCLEN_CHARFOUND_LEN(n);
 	c = rb_enc_mbc_to_codepoint(p, pend, enc);
 	p += n;
-	if (c == '"'|| c == '\\' ||
+	if ((asciicompat || unicode_p) &&
+	  (c == '"'|| c == '\\' ||
 	    (c == '#' &&
              p < pend &&
              MBCLEN_CHARFOUND_P(rb_enc_precise_mbclen(p,pend,enc)) &&
              (cc = rb_enc_codepoint(p,pend,enc),
-              (cc == '$' || cc == '@' || cc == '{')))) {
+              (cc == '$' || cc == '@' || cc == '{'))))) {
 	    if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
 	    str_buf_cat2(result, "\\");
 	    if (asciicompat || enc == resenc) {
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 30179)
+++ test/ruby/test_string.rb	(revision 30180)
@@ -1917,6 +1917,11 @@
     assert_equal('"abc\\"\\\\"', i, bug4081)
   end
 
+  def test_dummy_inspect
+    assert_equal('"\e\x24\x42\x22\x4C\x22\x68\e\x28\x42"',
+                 "\u{ffe2}\u{2235}".encode("cp50220").inspect)
+  end
+
   def test_prepend
     assert_equal(S("hello world!"), "world!".prepend("hello "))
 

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

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