Skip to content

Commit

Permalink
object.c: preserve encodings
Browse files Browse the repository at this point in the history
* object.c (rb_any_to_s, rb_obj_inspect): preserve encodings of class
  name and instance variable names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Aug 17, 2012
1 parent f7c2791 commit b421bd0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/ruby/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,13 @@ def test_to_s
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
Expand All @@ -713,6 +720,23 @@ def x.to_s
"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
Expand Down

0 comments on commit b421bd0

Please sign in to comment.