summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--object.c14
2 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 26efe7e..a54e479 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
-Sat Jun 21 21:27:18 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+Sat Jun 21 23:15:08 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
- * 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 <uema2x@jcom.home.ne.jp>
diff --git a/object.c b/object.c
index 1e7c5c1..33502db 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);
}