mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Warn suspicious flag to Regexp.new
Now second argument should be `true`, `false`, `nil` or Integer. This flag is confused with third argument some times.
This commit is contained in:
parent
a58611dfb1
commit
ab2a43265c
Notes:
git
2022-06-20 19:35:35 +09:00
4 changed files with 17 additions and 1 deletions
5
NEWS.md
5
NEWS.md
|
@ -118,6 +118,10 @@ Note: We're only listing outstanding class updates.
|
|||
* Proc#dup returns an instance of subclass. [[Bug #17545]]
|
||||
* Proc#parameters now accepts lambda keyword. [[Feature #15357]]
|
||||
|
||||
* Regexp
|
||||
* Regexp.new now warns second argument, other than `true`, `false`,
|
||||
`nil` or Integer. [[Feature #18788]]
|
||||
|
||||
* Refinement
|
||||
* Refinement#refined_class has been added. [[Feature #12737]]
|
||||
|
||||
|
@ -263,3 +267,4 @@ The following deprecated APIs are removed.
|
|||
[Bug #18625]: https://bugs.ruby-lang.org/issues/18625
|
||||
[Bug #18633]: https://bugs.ruby-lang.org/issues/18633
|
||||
[Bug #18782]: https://bugs.ruby-lang.org/issues/18782
|
||||
[Feature #18788]: https://bugs.ruby-lang.org/issues/18788
|
||||
|
|
|
@ -12057,12 +12057,15 @@ re.$(OBJEXT): $(hdrdir)/ruby.h
|
|||
re.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/array.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/bits.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/class.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/hash.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/object.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/ractor.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/re.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/serial.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/string.h
|
||||
re.$(OBJEXT): $(top_srcdir)/internal/time.h
|
||||
|
|
4
re.c
4
re.c
|
@ -20,6 +20,7 @@
|
|||
#include "internal/imemo.h"
|
||||
#include "internal/re.h"
|
||||
#include "internal/string.h"
|
||||
#include "internal/object.h"
|
||||
#include "internal/ractor.h"
|
||||
#include "internal/variable.h"
|
||||
#include "regint.h"
|
||||
|
@ -3716,7 +3717,8 @@ rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
|
|||
else {
|
||||
if (opts != Qundef) {
|
||||
if (FIXNUM_P(opts)) flags = FIX2INT(opts);
|
||||
else if (RTEST(opts)) flags = ONIG_OPTION_IGNORECASE;
|
||||
else if (!NIL_P(opts) && rb_bool_expected(opts, "ignorecase", FALSE))
|
||||
flags = ONIG_OPTION_IGNORECASE;
|
||||
}
|
||||
if (n_flag != Qundef && !NIL_P(n_flag)) {
|
||||
char *kcode = StringValuePtr(n_flag);
|
||||
|
|
|
@ -628,6 +628,12 @@ class TestRegexp < Test::Unit::TestCase
|
|||
assert_raise(RegexpError) { Regexp.new("((?<v>))\\g<0>") }
|
||||
end
|
||||
|
||||
def test_initialize_bool_warning
|
||||
assert_warning(/expected true or false as ignorecase/) do
|
||||
Regexp.new("foo", :i)
|
||||
end
|
||||
end
|
||||
|
||||
def test_match_control_meta_escape
|
||||
assert_equal(0, /\c\xFF/ =~ "\c\xFF")
|
||||
assert_equal(0, /\c\M-\xFF/ =~ "\c\M-\xFF")
|
||||
|
|
Loading…
Reference in a new issue