aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-22 11:31:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-22 11:31:13 +0000
commitf3b132faac3a6a777fb624b1a4c7bcb95c3eb625 (patch)
tree96da08d54bd2605c76160109382ee6d18fd7d06c
parent7815cbd7d0699ab0b9e50998882b7981acca8e07 (diff)
downloadruby-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--ChangeLog4
-rw-r--r--object.c4
-rw-r--r--test/ruby/test_module.rb5
3 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index c92347e427..2da27038de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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]
diff --git a/object.c b/object.c
index eb7df7eae3..896c6047f1 100644
--- a/object.c
+++ b/object.c
@@ -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