From 2b79366f5243fad65ad13005e12e78c88d3a95ba Mon Sep 17 00:00:00 2001 From: naruse Date: Sat, 11 Dec 2010 19:03:26 +0000 Subject: [PATCH] * string.c (rb_str_inspect): fix: extra back slash is added when the string is dummy encoding and includes \x22 or \x5C. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 5 +++-- test/ruby/test_string.rb | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1405c50f1b..29ef143cf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Dec 12 04:01:58 2010 NARUSE, Yui + + * 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 * ext/openssl/ossl_asn1.c: indefinite length BER to DER encoding is diff --git a/string.c b/string.c index ade48c65bd..e202291f08 100644 --- a/string.c +++ b/string.c @@ -4251,12 +4251,13 @@ rb_str_inspect(VALUE str) 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) { diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 16a6905667..972f326ab2 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1917,6 +1917,11 @@ class TestString < Test::Unit::TestCase 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 "))