[ruby-core:117799] [Ruby master Bug#20421] String#index and String#byteindex don't clear `$~` when offset > size (or bytesize)
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2024-05-07 20:48:52 UTC
List:
ruby-core #117799
Issue #20421 has been updated by Eregon (Benoit Daloze). Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: DONTNEED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONTNEED Given this is a clear bug (which can break programs' logic) I think it's good to backport. ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108205 * Author: andrykonchin (Andrew Konchin) * Status: Closed * ruby -v: 3.2.2 * Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONTNEED ---------------------------------------- When String#index and String#byteindex are called with Regexp and offset they clear `$~` (that contains result of the last Regexp matching) when offset < -size. But they don't clear `$~` when offset > size what seems inconsistent: ```ruby "a".index(/a/) p $~ # => #<MatchData "a"> string = "blablabla" string.index(/bla/, string.length + 1) p $~ # => #<MatchData "a"> ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- [email protected] To unsubscribe send an email to [email protected] ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/