Project

General

Profile

Actions

Bug #1553

closed

String#index Ignores Out-of-Range Offset When Given Regexp Matching the Empty String

Added by runpaint (Run Paint Run Run) almost 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2009-05-28 trunk 23601) [i686-linux]
Backport:
[ruby-core:23660]

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

Actions #1

Updated by yugui (Yuki Sonoda) over 14 years ago

  • Target version changed from 2.0.0 to 1.9.2

=begin

=end

Actions #2

Updated by naruse (Yui NARUSE) over 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24103.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0