mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
object.c: preserve encodings
* 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
This commit is contained in:
parent
f7c2791c60
commit
b421bd0e12
3 changed files with 35 additions and 5 deletions
|
@ -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
|
||||
|
|
11
object.c
11
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue