aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorKasumi Hanazuki <kasumi@rollingapple.net>2020-08-13 02:26:09 +0000
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-08-13 20:54:12 +0900
commit014a4fda54cb6897ed54ea9c44376db3459fc46e (patch)
treee9f9750eec6b6e644ddb0095b75fe779eb19c39f /test
parent5d71eed1a7f0a70db013de59cd7e95bdca0d5c0e (diff)
downloadruby-014a4fda54cb6897ed54ea9c44376db3459fc46e.tar.gz
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]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_string.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 308ba80373..489eee33dc 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1353,6 +1353,8 @@ CODE
assert_nil("foo".index(//, -100))
assert_nil($~)
+
+ assert_equal(2, S("abcdbce").index(/b\Kc/))
end
def test_insert
@@ -1525,6 +1527,8 @@ CODE
assert_equal(3, "foo".rindex(//))
assert_equal([3, 3], $~.offset(0))
+
+ assert_equal(5, S("abcdbce").rindex(/b\Kc/))
end
def test_rjust