diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-22 11:31:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-22 11:31:13 +0000 |
commit | f3b132faac3a6a777fb624b1a4c7bcb95c3eb625 (patch) | |
tree | 96da08d54bd2605c76160109382ee6d18fd7d06c | |
parent | 7815cbd7d0699ab0b9e50998882b7981acca8e07 (diff) | |
download | ruby-f3b132faac3a6a777fb624b1a4c7bcb95c3eb625.tar.gz |
object.c: no nested symbol
* object.c (rb_mod_const_get): symbol cannot be nested constant name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | object.c | 4 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 5 |
3 files changed, 11 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Sat Dec 22 20:31:10 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * object.c (rb_mod_const_get): symbol cannot be nested constant name. + Sat Dec 22 19:26:35 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> * object.c (rb_mod_const_get): check more strictly. [ruby-dev:46748] @@ -1901,6 +1901,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) rb_encoding *enc; const char *pbeg, *p, *path, *pend; ID id; + int nestable = 1; if (argc == 1) { name = argv[0]; @@ -1912,6 +1913,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) if (SYMBOL_P(name)) { name = rb_sym_to_s(name); + nestable = 0; } name = rb_check_string_type(name); @@ -1933,6 +1935,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) } if (p + 2 < pend && p[0] == ':' && p[1] == ':') { + if (!nestable) goto wrong_name; mod = rb_cObject; p += 2; pbeg = p; @@ -1949,6 +1952,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) id = rb_check_id_cstr(pbeg, len = p-pbeg, enc); if (p < pend && p[0] == ':') { + if (!nestable) goto wrong_name; if (p + 2 >= pend || p[1] != ':') goto wrong_name; p += 2; pbeg = p; diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 84dedb431b..8afb34ae78 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -271,9 +271,10 @@ class TestModule < Test::Unit::TestCase def test_nested_get_symbol const = [self.class, Other].join('::').to_sym + assert_raise(NameError) {Object.const_get(const)} - assert_equal Other, Object.const_get(const) - assert_equal User::USER, self.class.const_get([User, 'USER'].join('::')) + const = [User, 'USER'].join('::').to_sym + assert_raise(NameError) {self.class.const_get(const)} end def test_nested_get_const_missing |