зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
7815cbd7d0
Коммит
f3b132faac
|
@ -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]
|
||||
|
|
4
object.c
4
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;
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче