diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2024-05-09 11:56:51 +0200 |
|---|---|---|
| committer | Benoit Daloze <eregontp@gmail.com> | 2024-05-14 09:29:21 +0200 |
| commit | 449899b38314d0ecbe61e42d34398bdf2561b8e9 (patch) | |
| tree | 4fc45c44200c8cfda309056081ae61fc43a8c855 /string.c | |
| parent | a10a0d0c77826b97ec246274adcc80952049688b (diff) | |
Fix `String#index` to clear MatchData when a regexp is passed
[Bug #20421]
The bug was fixed in Ruby 3.3 via 9dcdffb8bf8a3654fd78bf1a58b30c8e13888a7a
Diffstat (limited to 'string.c')
| -rw-r--r-- | string.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -3993,8 +3993,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)); |
