summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 17:10:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-22 17:10:00 +0000
commitbd6fe32691d7f71facd96c7e059161bd98946887 (patch)
tree1685c7f9a014271bcaa5fff7bbf2c2782aae33bc /string.c
parent4e5114b0d17aff091267656705c3586ed24b9e1c (diff)
string.c: $; name in error message
* string.c (rb_str_split_m): show $; name in error message when it is a wrong object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/string.c b/string.c
index bc504ec3ed..f74cbaafd1 100644
--- a/string.c
+++ b/string.c
@@ -7003,6 +7003,16 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
return INT2NUM(i);
}
+static VALUE
+rb_fs_check(VALUE val)
+{
+ if (!NIL_P(val) && !RB_TYPE_P(val, T_STRING) && !RB_TYPE_P(val, T_REGEXP)) {
+ val = rb_check_string_type(val);
+ if (NIL_P(val)) return 0;
+ }
+ return val;
+}
+
static const char isspacetable[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -7094,11 +7104,17 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
}
enc = STR_ENC_GET(str);
- if (NIL_P(spat) && NIL_P(spat = rb_fs)) {
+ split_type = regexp;
+ if (!NIL_P(spat)) {
+ spat = get_pat_quoted(spat, 0);
+ }
+ else if (NIL_P(spat = rb_fs)) {
split_type = awk;
}
- else {
- spat = get_pat_quoted(spat, 0);
+ else if (!(spat = rb_fs_check(spat))) {
+ rb_raise(rb_eTypeError, "value of $; must be String or Regexp");
+ }
+ if (split_type != awk) {
if (BUILTIN_TYPE(spat) == T_STRING) {
rb_encoding *enc2 = STR_ENC_GET(spat);
@@ -7122,9 +7138,6 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
}
}
}
- else {
- split_type = regexp;
- }
}
result = rb_ary_new();