array.c: class name encoding

* array.c (rb_ary_bsearch): preserve encoding of class name in an
  exception message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-01-11 23:48:10 +00:00
parent cb95d38a7a
commit 4d69e03b66
2 changed files with 10 additions and 6 deletions

View File

@ -2621,9 +2621,9 @@ rb_ary_bsearch(VALUE ary)
} }
} }
else { else {
rb_raise(rb_eTypeError, "wrong argument type %s" rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE
" (must be numeric, true, false or nil)", " (must be numeric, true, false or nil)",
rb_obj_classname(v)); rb_obj_class(v));
} }
if (smaller) { if (smaller) {
high = mid; high = mid;

View File

@ -2458,6 +2458,10 @@ class TestArray < Test::Unit::TestCase
assert_raise(TypeError) do assert_raise(TypeError) do
[1, 2, 42, 100, 666].bsearch{ "not ok" } [1, 2, 42, 100, 666].bsearch{ "not ok" }
end end
c = eval("class C\u{309a 26a1 26c4 1f300};self;end")
assert_raise_with_message(TypeError, /C\u{309a 26a1 26c4 1f300}/) do
[0,1].bsearch {c.new}
end
assert_equal [1, 2, 42, 100, 666].bsearch{}, [1, 2, 42, 100, 666].bsearch{false} assert_equal [1, 2, 42, 100, 666].bsearch{}, [1, 2, 42, 100, 666].bsearch{false}
end end