ruby-changes:39094
From: nobu <ko1@a...>
Date: Tue, 7 Jul 2015 12:49:35 +0900 (JST)
Subject: [ruby-changes:39094] nobu:r51175 (trunk): symbol.c: preserve encoding
nobu 2015-07-07 12:49:14 +0900 (Tue, 07 Jul 2015) New Revision: 51175 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51175 Log: symbol.c: preserve encoding * symbol.c (rb_check_id, rb_check_symbol): preserve encoding of the given name. Modified files: trunk/symbol.c trunk/test/-ext-/symbol/test_type.rb trunk/test/ruby/test_method.rb Index: symbol.c =================================================================== --- symbol.c (revision 51174) +++ symbol.c (revision 51175) @@ -963,9 +963,8 @@ rb_check_id(volatile VALUE *namep) https://github.com/ruby/ruby/blob/trunk/symbol.c#L963 else if (!RB_TYPE_P(name, T_STRING)) { tmp = rb_check_string_type(name); if (NIL_P(tmp)) { - tmp = rb_inspect(name); - rb_raise(rb_eTypeError, "%s is not a symbol nor a string", - RSTRING_PTR(tmp)); + rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string", + name); } name = tmp; *namep = name; @@ -996,9 +995,8 @@ rb_check_symbol(volatile VALUE *namep) https://github.com/ruby/ruby/blob/trunk/symbol.c#L995 else if (!RB_TYPE_P(name, T_STRING)) { tmp = rb_check_string_type(name); if (NIL_P(tmp)) { - tmp = rb_inspect(name); - rb_raise(rb_eTypeError, "%s is not a symbol nor a string", - RSTRING_PTR(tmp)); + rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol nor a string", + name); } name = tmp; *namep = name; Index: test/ruby/test_method.rb =================================================================== --- test/ruby/test_method.rb (revision 51174) +++ test/ruby/test_method.rb (revision 51175) @@ -251,6 +251,13 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L251 m = o.method(:bar).unbind assert_raise(TypeError) { m.bind(Object.new) } + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1f431}/) { + o.method(cx) + } + end + + def test_bind_module_instance_method feature4254 = '[ruby-core:34267]' m = M.instance_method(:meth) assert_equal(:meth, m.bind(Object.new).call, feature4254) @@ -276,6 +283,10 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L283 assert_raise(TypeError) do Class.new.class_eval { define_method(:bar, o.method(:bar)) } end + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) { + Class.new {define_method(cx) {}} + } end def test_define_method_no_proc Index: test/-ext-/symbol/test_type.rb =================================================================== --- test/-ext-/symbol/test_type.rb (revision 51174) +++ test/-ext-/symbol/test_type.rb (revision 51175) @@ -120,5 +120,19 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_type.rb#L120 assert_symtype(Bug::Symbol.attrset("foo!="), :attrset?) assert_equal(:"foo!=", Bug::Symbol.attrset(:foo!)) end + + def test_check_id_invalid_type + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) { + Bug::Symbol.pinneddown?(cx) + } + end + + def test_check_symbol_invalid_type + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) { + Bug::Symbol.find(cx) + } + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/