[ruby-core:117494] [Ruby master Bug#20421] String#index and String#byteindex don't clear `$~` when offset > size (or bytesize)

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/

Issue #20421 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Closed Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: DONTNEED The issue doesn't affect 3.3 and master. It appears fixed by commit:9dcdffb8bf8a3654fd78bf1a58b30c8e13888a7a. If you would like the fix backported to 3.2, please respond. ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108200 * Author: andrykonchin (Andrew Konchin) * Status: Closed * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 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/

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/

Issue #20421 has been updated by Eregon (Benoit Daloze). We should also add a test so this doesn't regress on 3.3 & master, that seems fine as a `ruby_bug` spec in ruby/spec. ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108206 * 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/

Issue #20421 has been updated by byroot (Jean Boussier). I got a ruby-bug spec at https://github.com/ruby/ruby/pull/10750 As for 9dcdffb8bf8a3654fd78bf1a58b30c8e13888a7a, it might make sense to make a more targeted fix for backport, as this is a more general refactor. ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108225 * Author: andrykonchin (Andrew Konchin) * Status: Closed * ruby -v: 3.2.2 * Backport: 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/

Issue #20421 has been updated by byroot (Jean Boussier). Here's more targeted patch for Ruby 3.2: https://github.com/ruby/ruby/pull/10751 ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108227 * Author: andrykonchin (Andrew Konchin) * Status: Closed * ruby -v: 3.2.2 * Backport: 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/

Issue #20421 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONTNEED to 3.1: REQUIRED, 3.2: DONE, 3.3: DONTNEED Thank you for the PR. I agree that the patch is good to backport. PR merged at 449899b38314d0ecbe61e42d34398bdf2561b8e9. ---------------------------------------- Bug #20421: String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) https://bugs.ruby-lang.org/issues/20421#change-108289 * Author: andrykonchin (Andrew Konchin) * Status: Closed * ruby -v: 3.2.2 * Backport: 3.1: REQUIRED, 3.2: DONE, 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/
participants (5)
-
andrykonchin (Andrew Konchin)
-
byroot (Jean Boussier)
-
Eregon (Benoit Daloze)
-
jeremyevans0 (Jeremy Evans)
-
nagachika (Tomoyuki Chikanaga)