summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--object.c11
-rw-r--r--test/ruby/test_object.rb24
3 files changed, 35 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 131849e912..677c4221c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Aug 17 23:28:54 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * object.c (rb_any_to_s, rb_obj_inspect): preserve encodings of class
+ name and instance variable names.
+
Fri Aug 17 12:39:33 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/dl/lib/dl/func.rb (DL::Function#bind): allow to return/break from
diff --git a/object.c b/object.c
index 73f76fa753..d487fe82cc 100644
--- a/object.c
+++ b/object.c
@@ -370,10 +370,10 @@ rb_obj_init_dup_clone(VALUE obj, VALUE orig)
VALUE
rb_any_to_s(VALUE obj)
{
- const char *cname = rb_obj_classname(obj);
VALUE str;
+ VALUE cname = rb_class_name(CLASS_OF(obj));
- str = rb_sprintf("#<%s:%p>", cname, (void*)obj);
+ str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj);
OBJ_INFECT(str, obj);
return str;
@@ -484,11 +484,12 @@ rb_obj_inspect(VALUE obj)
{
if (rb_ivar_count(obj) > 0) {
VALUE str;
- const char *c = rb_obj_classname(obj);
+ VALUE c = rb_class_name(CLASS_OF(obj));
- str = rb_sprintf("-<%s:%p", c, (void*)obj);
+ str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
return rb_exec_recursive(inspect_obj, obj, str);
- } else {
+ }
+ else {
return rb_any_to_s(obj);
}
}
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 61482f7c1a..b8edd24670 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -688,6 +688,13 @@ class TestObject < Test::Unit::TestCase
s = x.to_s
assert_equal(true, s.untrusted?)
assert_equal(true, s.tainted?)
+
+ x = eval(<<-EOS)
+ class ToS\u{3042}
+ new.to_s
+ end
+ EOS
+ assert_match(/\bToS\u{3042}:/, x)
end
def test_inspect
@@ -713,6 +720,23 @@ class TestObject < Test::Unit::TestCase
"to_s"
end
assert_match(/\A#<Object:0x\h+>\z/, x.inspect, feature6130)
+
+ x = eval(<<-EOS)
+ class Inspect\u{3042}
+ new.inspect
+ end
+ EOS
+ assert_match(/\bInspect\u{3042}:/, x)
+
+ x = eval(<<-EOS)
+ class Inspect\u{3042}
+ def initialize
+ @\u{3044} = 42
+ end
+ new.inspect
+ end
+ EOS
+ assert_match(/\bInspect\u{3042}:.* @\u{3044}=42\b/, x)
end
def test_exec_recursive