summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2024-05-09 11:56:51 +0200
committerBenoit Daloze <eregontp@gmail.com>2024-05-14 09:29:21 +0200
commit449899b38314d0ecbe61e42d34398bdf2561b8e9 (patch)
tree4fc45c44200c8cfda309056081ae61fc43a8c855 /string.c
parenta10a0d0c77826b97ec246274adcc80952049688b (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.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index 1f7321a1ce..ed51fa4af7 100644
--- a/string.c
+++ b/string.c
@@ -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));