mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
[Bug #19746] String#index
with regexp should clear $~
unless matched
This commit is contained in:
parent
9e709d0f4a
commit
0cbfeb8210
Notes:
git
2023-06-28 05:06:47 +00:00
2 changed files with 10 additions and 2 deletions
8
string.c
8
string.c
|
@ -3880,8 +3880,10 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
|
||||
if (RB_TYPE_P(sub, T_REGEXP)) {
|
||||
if (pos > str_strlen(str, NULL))
|
||||
if (pos > str_strlen(str, NULL)) {
|
||||
rb_backref_set(Qnil);
|
||||
return Qnil;
|
||||
}
|
||||
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
|
||||
rb_enc_check(str, sub), single_byte_optimizable(str));
|
||||
|
||||
|
@ -3989,8 +3991,10 @@ rb_str_byteindex_m(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
|
||||
if (RB_TYPE_P(sub, T_REGEXP)) {
|
||||
if (pos > RSTRING_LEN(str))
|
||||
if (pos > RSTRING_LEN(str)) {
|
||||
rb_backref_set(Qnil);
|
||||
return Qnil;
|
||||
}
|
||||
if (rb_reg_search(sub, str, pos, 0) < 0) {
|
||||
return Qnil;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue