From 93ad576b0511ee435c01bd92e31d625d29c2c22e Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 18 Aug 2008 15:56:38 +0000 Subject: [PATCH] * re.c (rb_reg_inspect): don't raise for uninitialized Regexp. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ re.c | 4 +++- test/ruby/test_regexp.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f2ef59bd7..a107dc8b53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue Aug 19 00:56:01 2008 Tanaka Akira + + * re.c (rb_reg_inspect): don't raise for uninitialized Regexp. + Tue Aug 19 00:34:24 2008 Tanaka Akira * io.c (rb_io_check_readable): side effect for STDIN removed. diff --git a/re.c b/re.c index ff82636a46..de7ebeb41b 100644 --- a/re.c +++ b/re.c @@ -435,7 +435,9 @@ rb_reg_source(VALUE re) static VALUE rb_reg_inspect(VALUE re) { - rb_reg_check(re); + if (!RREGEXP(re)->ptr || !RREGEXP_SRC(re) || !RREGEXP_SRC_PTR(re)) { + return rb_any_to_s(re); + } return rb_reg_desc(RREGEXP_SRC_PTR(re), RREGEXP_SRC_LEN(re), re); } diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index bce362e34f..ad222c5483 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -686,7 +686,7 @@ class TestRegexp < Test::Unit::TestCase assert_nil(~Regexp.allocate) assert_raise(TypeError) { Regexp.allocate.match("") } assert_raise(TypeError) { Regexp.allocate.to_s } - assert_raise(TypeError) { Regexp.allocate.inspect } + assert_match(/^#$/, Regexp.allocate.inspect) assert_raise(TypeError) { Regexp.allocate.source } assert_raise(TypeError) { Regexp.allocate.casefold? } assert_raise(TypeError) { Regexp.allocate.options }