From 2a22a6b2d8465934e75520a7fdcf522d50890caf Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Thu, 17 Oct 2019 17:44:46 +0900 Subject: Regexp#match{?} with nil raises TypeError as String, Symbol (#1506) * {String|Symbol}#match{?} with nil returns falsy To improve consistency with Regexp#match{?} * String#match(nil) returns `nil` instead of TypeError * String#match?(nil) returns `false` instead of TypeError * Symbol#match(nil) returns `nil` instead of TypeError * Symbol#match?(nil) returns `false` instead of TypeError * Prefer exception * Follow empty ENV * Drop outdated specs * Write ruby/spec for above https://github.com/ruby/ruby/pull/1506/files#r183242981 * Fix merge miss --- re.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 're.c') diff --git a/re.c b/re.c index 436316c2d4..92eba92d1b 100644 --- a/re.c +++ b/re.c @@ -3323,6 +3323,7 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re) pos = 0; } + str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str); pos = reg_match_pos(re, &str, pos); if (pos < 0) { rb_backref_set(Qnil); @@ -3368,7 +3369,6 @@ rb_reg_match_p(VALUE re, VALUE str, long pos) const UChar *start, *end; int tmpreg; - if (NIL_P(str)) return Qfalse; str = SYMBOL_P(str) ? rb_sym2str(str) : StringValue(str); if (pos) { if (pos < 0) { -- cgit v1.2.3