From e6340674d16049c9d93270d00a93941abe557e64 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 13 Sep 2006 08:19:54 +0000 Subject: [PATCH] * string.c (rb_str_intern): allow symbols to contains nul. * string.c (sym_inspect): symbol may contain nul. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2acdf64509..c32d3c0df7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ Wed Sep 13 16:43:36 2006 Yukihiro Matsumoto * string.c (rb_str_intern): prohibit interning tainted string. + * string.c (rb_str_intern): allow symbols to contains nul. + + * string.c (sym_inspect): symbol may contain nul. + Wed Sep 13 01:14:02 2006 Nobuyoshi Nakada * lib/optparse.rb (OptionParser#getopts): works with pre-registered diff --git a/string.c b/string.c index 332b6186dd..43d4f40747 100644 --- a/string.c +++ b/string.c @@ -4151,12 +4151,10 @@ rb_str_intern(VALUE s) if (!RSTRING_PTR(str) || RSTRING_LEN(str) == 0) { rb_raise(rb_eArgError, "interning empty string"); } - if (strlen(RSTRING_PTR(str)) != RSTRING_LEN(str)) - rb_raise(rb_eArgError, "symbol string may not contain `\\0'"); if (OBJ_TAINTED(str)) { rb_raise(rb_eSecurityError, "Insecure: can't intern tainted string"); } - id = rb_intern(RSTRING_PTR(str)); + id = rb_intern2(RSTRING_PTR(str), RSTRING_LEN(str)); return ID2SYM(id); } @@ -4482,7 +4480,8 @@ sym_inspect(VALUE sym) str = rb_str_new(0, RSTRING_LEN(sym)+1); RSTRING_PTR(str)[0] = ':'; memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym)); - if (!rb_symname_p(RSTRING_PTR(sym))) { + if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(sym)) || + !rb_symname_p(RSTRING_PTR(sym))) { str = rb_str_dump(str); strncpy(RSTRING_PTR(str), ":\"", 2); } @@ -4580,7 +4579,7 @@ rb_to_id(VALUE name) } break; case T_SYMBOL: - id = SYM2ID(name); + return SYM2ID(name); break; default: tmp = rb_check_string_type(name);