diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-22 12:06:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-22 12:06:42 +0000 |
commit | 34918aa83260246e545911efe6e1672507c3e699 (patch) | |
tree | 8815d9f98358df4f59fc18a49a43e2a81f03e7d3 /test/ruby | |
parent | c276b7380499eb5b181eca838ec86fc480d4ac94 (diff) | |
download | ruby-34918aa83260246e545911efe6e1672507c3e699.tar.gz |
* object.c (rb_mod_{const,cvar}_defined, rb_obj_ivar_defined):
avoid inadvertent symbol creation in reflection methods. based
on a patch by Jeremy Evans at [ruby-core:38367]. [Feature #5072]
* vm_method.c (rb_mod_method_defined)
(rb_mod_{public,private,protected}_method_defined)
(obj_respond_to): ditto.
* parse.y (rb_check_id): new function returns already interned ID
or 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_module.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index e6c107961d..1aa7f8c691 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -495,6 +495,9 @@ class TestModule < Test::Unit::TestCase def test_const_get_invalid_name c1 = Class.new assert_raise(NameError) { c1.const_defined?(:foo) } + name = "gadzooks" + assert !Symbol.all_symbols.any? {|sym| sym.to_s == name} + assert_raise(NameError) { c1.const_defined?(name) } end def test_const_get_no_inherited diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 9061f191bf..282964cdf5 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -144,4 +144,19 @@ class TestSymbol < Test::Unit::TestCase assert_equal(':"\\u3042\\u3044\\u3046"', "\u3042\u3044\u3046".encode(e).to_sym.inspect) end end + + def test_no_inadvertent_symbol_creation + feature5072 = '[ruby-core:38367]' + c = Class.new + s = "gadzooks" + {:respond_to? => "#{s}1", :method_defined? => "#{s}2", + :public_method_defined? => "#{s}3", :private_method_defined? => "#{s}4", + :protected_method_defined? => "#{s}5", :const_defined? => "A#{s}", + :instance_variable_defined? => "@#{s}", :class_variable_defined? => "@@#{s}" + }.each do |meth, str| + msg = "#{meth}(#{str}) #{feature5072}" + assert !c.send(meth, str), msg + assert !Symbol.all_symbols.any? {|sym| sym.to_s == str}, msg + end + end end |