summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-03-05 20:27:28 +0900
committerGitHub <[email protected]>2017-03-05 20:27:28 +0900
commitd050694580e99bc5699da36640d8ce2b4e93c5d0 (patch)
tree019001f5d1a3a0185f0f14886f169fbc7e7c9763
parent4f43db862a19df01720f72cc91925a497c7d7f45 (diff)
parent76e10351faa20301f73a333b13f94a41059baf14 (diff)
downloadmruby-d050694580e99bc5699da36640d8ce2b4e93c5d0.tar.gz
mruby-d050694580e99bc5699da36640d8ce2b4e93c5d0.zip
Merge pull request #3483 from ksss/string-index
String#index shouldn't return nil when "".index ""
-rw-r--r--src/string.c2
-rw-r--r--test/t/string.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c
index 9efc89b34..c36b7524a 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1608,7 +1608,7 @@ mrb_str_index(mrb_state *mrb, mrb_value str)
return mrb_nil_value();
}
}
- if (pos >= clen) return mrb_nil_value();
+ if (pos > clen) return mrb_nil_value();
pos = chars2bytes(str, 0, pos);
switch (mrb_type(sub)) {
diff --git a/test/t/string.rb b/test/t/string.rb
index 20dc49d92..442c95bf7 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -402,6 +402,8 @@ assert('String#index', '15.2.10.5.22') do
assert_equal 0, 'abc'.index('a')
assert_nil 'abc'.index('d')
assert_equal 3, 'abcabc'.index('a', 1)
+ assert_equal 5, "hello".index("", 5)
+ assert_equal nil, "hello".index("", 6)
end
assert('String#initialize', '15.2.10.5.23') do