From ab2a43265cfdda288d1baaa29936fd408c2a42bc Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 24 May 2022 16:51:15 +0900 Subject: 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. --- re.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 're.c') diff --git a/re.c b/re.c index e9bcf11b31..f225a413d5 100644 --- a/re.c +++ b/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); -- cgit v1.2.1