[ruby-core:117494] [Ruby master Bug#20421] String#index and String#byteindex don't clear `$~` when offset > size (or bytesize)
From:
"andrykonchin (Andrew Konchin) via ruby-core" <ruby-core@...>
Date:
2024-04-11 15:57:06 UTC
List:
ruby-core #117494
Issue #20421 has been reported by andrykonchin (Andrew Konchin). ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421 * Author: andrykonchin (Andrew Konchin) * Status: Open * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- 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 not consistent: ```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/