diff --git a/ChangeLog b/ChangeLog index 26efe7edd6..a54e479859 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ -Sat Jun 21 21:27:18 2003 Nobuyoshi Nakada +Sat Jun 21 23:15:08 2003 Yukihiro Matsumoto - * object.c (rb_to_id): use rb_str_intern() instead of rb_intern() - directly, for sanity check. + * object.c (str_to_id): check for empty string before intern. + [ruby-talk:74006] Sat Jun 21 13:56:09 2003 Takaaki Uematsu diff --git a/object.c b/object.c index 1e7c5c1d45..33502dbc3b 100644 --- a/object.c +++ b/object.c @@ -779,6 +779,16 @@ rb_class_superclass(klass) return super; } +static ID +str_to_id(str) + VALUE str; +{ + if (!RSTRING(str)->ptr || RSTRING(str)->len == 0) { + rb_raise(rb_eArgError, "empty symbol string"); + } + return rb_intern(RSTRING(str)->ptr); +} + ID rb_to_id(name) VALUE name; @@ -788,7 +798,7 @@ rb_to_id(name) switch (TYPE(name)) { case T_STRING: - return rb_str_intern(name); + return str_to_id(name); case T_FIXNUM: rb_warn("do not use Fixnums as Symbols"); id = FIX2LONG(name); @@ -802,7 +812,7 @@ rb_to_id(name) default: tmp = rb_check_string_type(name); if (!NIL_P(tmp)) { - return rb_str_intern(tmp); + return str_to_id(tmp); } rb_raise(rb_eTypeError, "%s is not a symbol", RSTRING(rb_inspect(name))->ptr); }