summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c6
-rw-r--r--test/ruby/test_string.rb2
3 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index c001a3444e..6bf7f81361 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Nov 22 18:33:30 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_inspect): append for each chars instead of bulk
+ copy if encoding conversion is needed. [ruby-core:33283]
+
Mon Nov 22 14:22:45 2010 NARUSE, Yui <naruse@ruby-lang.org>
* time.c (time_zone): use rb_locale_str_new_cstr to set encoding
diff --git a/string.c b/string.c
index 20466e16f2..307056cee7 100644
--- a/string.c
+++ b/string.c
@@ -4238,8 +4238,10 @@ rb_str_inspect(VALUE str)
(cc == '$' || cc == '@' || cc == '{')))) {
if (p - n > prev) str_buf_cat(result, prev, p - n - prev);
str_buf_cat2(result, "\\");
- prev = p - n;
- continue;
+ if (enc == resenc) {
+ prev = p - n;
+ continue;
+ }
}
switch (c) {
case '\n': cc = 'n'; break;
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index c024b58ed8..0c75f31311 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1890,10 +1890,12 @@ class TestString < Test::Unit::TestCase
end
def test_ascii_incomat_inspect
+ bug4081 = '[ruby-core:33283]'
[Encoding::UTF_16LE, Encoding::UTF_16BE,
Encoding::UTF_32LE, Encoding::UTF_32BE].each do |e|
assert_equal('"abc"', "abc".encode(e).inspect)
assert_equal('"\\u3042\\u3044\\u3046"', "\u3042\u3044\u3046".encode(e).inspect)
+ assert_equal('"ab\\"c"', "ab\"c".encode(e).inspect, bug4081)
end
end