From 3df94d7b5d7129d50443b77f869835b958423fd5 Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 29 Jan 2013 22:15:23 +0000 Subject: [PATCH] * re.c (reg_operand): Simplify and reuse error handling [Bug #7539] * test/ruby/test_regexp.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ re.c | 7 +------ test/ruby/test_regexp.rb | 7 +++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e067a64ee..8e2d720dbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jan 30 07:15:04 2013 Marc-Andre Lafortune + + * re.c (reg_operand): Simplify and reuse error handling [Bug #7539] + + * test/ruby/test_regexp.rb: Test for above + Wed Jan 30 07:00:16 2013 Marc-Andre Lafortune * object.c: Improve error for failed implicit conversions [Bug #7539] diff --git a/re.c b/re.c index 17612d48f4..4e57971364 100644 --- a/re.c +++ b/re.c @@ -2667,12 +2667,7 @@ reg_operand(VALUE s, int check) return rb_sym_to_s(s); } else { - VALUE tmp = rb_check_string_type(s); - if (check && NIL_P(tmp)) { - rb_raise(rb_eTypeError, "can't convert %s to String", - rb_obj_classname(s)); - } - return tmp; + return (check ? rb_str_to_str : rb_check_string_type)(s); } } diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index e9c866a9ca..308b30ae9c 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -929,4 +929,11 @@ class TestRegexp < Test::Unit::TestCase # use Regexp.new instead of literal to ignore a parser warning. check(Regexp.new('[0-1-\\s]'), [' ', '-'], ['2', 'a'], bug6853) end + + def test_error_message_on_failed_conversion + bug7539 = '[ruby-core:50733]' + assert_equal false, /x/=== 42 + err = assert_raise(TypeError){ Regexp.quote(42) } + assert_equal 'no implicit conversion of Fixnum into String', err.message, bug7539 + end end