From: "byroot (Jean Boussier) via ruby-core" Date: 2024-05-09T10:33:19+00:00 Subject: [ruby-core:117818] [Ruby master Bug#20421] String#index and String#byteindex don't clear `$~` when offset > size (or bytesize) 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 $~ # => # string = "blablabla" string.index(/bla/, string.length + 1) p $~ # => # ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/