summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/string.c b/string.c
index 47026d40f3..cc82c7fb57 100644
--- a/string.c
+++ b/string.c
@@ -892,10 +892,6 @@ rb_str_index_m(argc, argv, str)
pos = rb_reg_search(sub, str, pos, 0);
break;
- case T_STRING:
- pos = rb_str_index(str, sub, pos);
- break;
-
case T_FIXNUM:
{
int c = FIX2INT(sub);
@@ -908,9 +904,20 @@ rb_str_index_m(argc, argv, str)
return Qnil;
}
- default:
- rb_raise(rb_eTypeError, "type mismatch: %s given",
- rb_class2name(CLASS_OF(sub)));
+ default: {
+ VALUE tmp;
+
+ tmp = rb_check_string_type(sub);
+ if (NIL_P(tmp)) {
+ rb_raise(rb_eTypeError, "type mismatch: %s given",
+ rb_class2name(CLASS_OF(sub)));
+ }
+ sub = tmp;
+ }
+ /* fall through */
+ case T_STRING:
+ pos = rb_str_index(str, sub, pos);
+ break;
}
if (pos == -1) return Qnil;