Bug #1553
closedString#index Ignores Out-of-Range Offset When Given Regexp Matching the Empty String
Description
=begin
On Ruby 1.9 String#index(Regexp, Fixnum) ignores the Fixnum offset when the Regexp matches the empty string and the offset represents a position outside the string. In this case it returns the position of the last match in the string, which is obviously its final character.
I expect this invocation to return nil because the documentation states "If the second parameter is present, it specifies the position in the string to begin the search." If the position is outside of the string the search shouldn't even begin, and thus must return nil. This expectation is reinforced by a non-empty, non-matching Regexp paired with an out-of-range offset returning nil.
1.8.7 returns nil for this scenario.
$ ruby -ve 'p "ruby".index(//,7)'
ruby 1.9.2dev (2009-05-28 trunk 23601) [i686-linux]
4
$ ruby1.8 -ve 'p "ruby".index(//,7)'
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
nil
$ ruby -ve 'p "ruby".index(/y/,7)'
ruby 1.9.2dev (2009-05-28 trunk 23601) [i686-linux]
nil
$ ruby1.8 -ve 'p "ruby".index(/y/,7)'
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
nil
=end