[ruby-core:95656] [Ruby master Feature#13083] {String|Symbol}#match{?} with nil returns falsy as Regexp#match{?} since ruby 3.0
From:
shugo@...
Date:
2019-11-03 00:35:54 UTC
List:
ruby-core #95656
Issue #13083 has been updated by shugo (Shugo Maeda).
matz (Yukihiro Matsumoto) wrote:
> Thank you for the input. If you can provide a more detailed situation, it would be better.
My situation is the same as Rafael's, and I fixed my code using the safe navigation operator:
https://github.com/shugo/textbringer/commit/c859d13
Code like `/regex/ =~ str` has often been used when `str` may be `nil`, and such code has been rewritten using Regexp#match? after Ruby 2.4.
This change will break all such code.
----------------------------------------
Feature #13083: {String|Symbol}#match{?} with nil returns falsy as Regexp#match{?} since ruby 3.0
https://bugs.ruby-lang.org/issues/13083#change-82444
* Author: kachick (Kenichi Kamiya)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Just for consistency
* patch: https://github.com/ruby/ruby/pull/1506
* spec: https://github.com/ruby/spec/pull/380
Currently behaves as ( ruby --version: ruby 2.5.0dev (2016-12-28 trunk 57228) [x86_64-darwin16] )
~~~ ruby
'string'.__send__(:=~, nil) #=> nil
'string'.match(nil) #=> TypeError: wrong argument type nil (expected Regexp)
'string'.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp)
:symbol.__send__(:=~, nil) #=> nil
:symbol.match(nil) #=> TypeError: wrong argument type nil (expected Regexp)
:symbol.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp)
/regex/.__send__(:=~, nil) #=> nil
/regex/.match(nil) #=> nil
/regex/.match?(nil) #=> false
~~~
Expected to
~~~ruby
'string'.__send__(:=~, nil) #=> nil
'string'.match(nil) #=> nil
'string'.match?(nil) #=> false
:symbol.__send__(:=~, nil) #=> nil
:symbol.match(nil) #=> nil
:symbol.match?(nil) #=> false
/regex/.__send__(:=~, nil) #=> nil
/regex/.match(nil) #=> nil
/regex/.match?(nil) #=> false
~~~
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>