Permalink
Browse files

String#index shouldn't return nil when "".index ""

  • Loading branch information...
ksss committed Mar 5, 2017
1 parent 8b089c0 commit 76e10351faa20301f73a333b13f94a41059baf14
Showing with 3 additions and 1 deletion.
  1. +1 −1 src/string.c
  2. +2 −0 test/t/string.rb
View
@@ -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)) {
View
@@ -402,6 +402,8 @@ def to_str
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

0 comments on commit 76e1035

Please sign in to comment.