[前][次][番号順一覧][スレッド一覧]

ruby-changes:26502

From: nobu <ko1@a...>
Date: Sat, 22 Dec 2012 20:31:29 +0900 (JST)
Subject: [ruby-changes:26502] nobu:r38553 (trunk): object.c: no nested symbol

nobu	2012-12-22 20:31:13 +0900 (Sat, 22 Dec 2012)

  New Revision: 38553

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38553

  Log:
    object.c: no nested symbol
    
    * object.c (rb_mod_const_get): symbol cannot be nested constant name.

  Modified files:
    trunk/ChangeLog
    trunk/object.c
    trunk/test/ruby/test_module.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38552)
+++ ChangeLog	(revision 38553)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 22 20:31:10 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_mod_const_get): symbol cannot be nested constant name.
+
 Sat Dec 22 19:26:35 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* object.c (rb_mod_const_get): check more strictly.  [ruby-dev:46748]
Index: object.c
===================================================================
--- object.c	(revision 38552)
+++ object.c	(revision 38553)
@@ -1901,6 +1901,7 @@ rb_mod_const_get(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/object.c#L1901
     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, https://github.com/ruby/ruby/blob/trunk/object.c#L1913
 
     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, https://github.com/ruby/ruby/blob/trunk/object.c#L1935
     }
 
     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, https://github.com/ruby/ruby/blob/trunk/object.c#L1952
 	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;
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 38552)
+++ test/ruby/test_module.rb	(revision 38553)
@@ -271,9 +271,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L271
 
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]