Project

General

Profile

« Previous | Next » 

Revision 014a4fda

Added by hanazuki (Kasumi Hanazuki) almost 5 years ago

rb_str_{index,rindex}_m: Handle /\K/ in pattern

When the pattern Regexp given to String#index and String#rindex
contain a /\K/ (lookbehind) operator, these methods return the
position where the beginning of the lookbehind pattern matches, while
they are expected to return the position where the \K matches.

# without patch
"abcdbce".index(/b\Kc/)  # => 1
"abcdbce".rindex(/b\Kc/)  # => 4

This patch fixes this problem by using BEG(0) instead of the return
value of rb_reg_search.

# with patch
"abcdbce".index(/b\Kc/)  # => 2
"abcdbce".rindex(/b\Kc/)  # => 5

Fixes [Bug #17118]