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
This commit is contained in:
Kenichi Kamiya 2019-10-17 17:44:46 +09:00 committed by Kazuhiro NISHIYAMA
parent 41457dcbe0
commit 2a22a6b2d8
5 changed files with 41 additions and 15 deletions

View file

@ -2512,6 +2512,7 @@ CODE
def test_match_method
assert_equal("bar", "foobarbaz".match(/bar/).to_s)
assert_raise(TypeError) { "".match(nil) }
o = Regexp.new('foo')
def o.match(x, y, z); x + y + z; end
@ -2567,6 +2568,10 @@ CODE
assert_equal('backref', $&)
end
def test_match_p_nil
assert_raise(TypeError) { ''.match?(nil) }
end
def test_clear
s = "foo" * 100
s.clear