Project

General

Profile

Actions

Bug #20421

closed

String#index and String#byteindex don't clear `$~` when offset > size (or bytesize)

Added by andrykonchin (Andrew Konchin) 7 months ago. Updated 6 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:117494]

Description

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:

"a".index(/a/)
p $~ # => #<MatchData "a">

string = "blablabla"
string.index(/bla/, string.length + 1)
p $~ # => #<MatchData "a">
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0