From 4d69e03b667df09ecf1add84e6e148d26e289b80 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 11 Jan 2015 23:48:10 +0000 Subject: 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 --- array.c | 12 ++++++------ test/ruby/test_array.rb | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/array.c b/array.c index 0de7231121..27fa0d35a6 100644 --- a/array.c +++ b/array.c @@ -2615,15 +2615,15 @@ rb_ary_bsearch(VALUE ary) else if (rb_obj_is_kind_of(v, rb_cNumeric)) { const VALUE zero = INT2FIX(0); switch (rb_cmpint(rb_funcallv(v, id_cmp, 1, &zero), v, INT2FIX(0))) { - case 0: return val; - case 1: smaller = 1; break; - case -1: smaller = 0; + case 0: return val; + case 1: smaller = 1; break; + case -1: smaller = 0; } } else { - rb_raise(rb_eTypeError, "wrong argument type %s" - " (must be numeric, true, false or nil)", - rb_obj_classname(v)); + rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE + " (must be numeric, true, false or nil)", + rb_obj_class(v)); } if (smaller) { high = mid; diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 31f33dde1e..8c08acec7c 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2458,6 +2458,10 @@ class TestArray < Test::Unit::TestCase assert_raise(TypeError) do [1, 2, 42, 100, 666].bsearch{ "not ok" } 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} end -- cgit v1.2.3