summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-19 06:39:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-19 06:39:01 +0000
commit6ea002a7a28ac11424798f448f1765ccf0513b95 (patch)
tree53aac200b92c8e121fabd1f1ae65ffb765c015d1
parent0fc6877ed5e2ef9f81cbbab488acc2f94912e116 (diff)
variable.c: exclude private constants
* variable.c (rb_local_constants_i): exclude private constants when excluding inherited constants too. [Bug #12345] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_module.rb2
-rw-r--r--variable.c2
3 files changed, 8 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7a822442018..23394ccd1cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jul 19 15:38:59 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * variable.c (rb_local_constants_i): exclude private constants
+ when excluding inherited constants too. [Bug #12345]
+
Sun Jul 17 23:42:00 2016 Kenta Murata <mrkn@mrkn.jp>
* numeric.c (num_finite_p, num_infinite_p): Add Numeric#finite? and
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 92c3dfd6eb2..0f9351c57d3 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1423,6 +1423,8 @@ class TestModule < Test::Unit::TestCase
def test_constants_with_private_constant
assert_not_include(::TestModule.constants, :PrivateClass)
+ assert_not_include(::TestModule.constants(true), :PrivateClass)
+ assert_not_include(::TestModule.constants(false), :PrivateClass)
end
def test_toplevel_private_constant
diff --git a/variable.c b/variable.c
index 4d3222b5dbf..09666856908 100644
--- a/variable.c
+++ b/variable.c
@@ -2399,7 +2399,7 @@ sv_i(ID key, VALUE v, void *a)
static enum rb_id_table_iterator_result
rb_local_constants_i(ID const_name, VALUE const_value, void *ary)
{
- if (rb_is_const_id(const_name)) {
+ if (rb_is_const_id(const_name) && !RB_CONST_PRIVATE_P((rb_const_entry_t *)const_value)) {
rb_ary_push((VALUE)ary, ID2SYM(const_name));
}
return ID_TABLE_CONTINUE;