1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Disallow use of attrset symbols as Struct members

Fixes [Bug #11326]
This commit is contained in:
Jeremy Evans 2019-07-05 10:01:06 -07:00
parent 01b723ba6d
commit e51dca2596
2 changed files with 7 additions and 0 deletions

View file

@ -551,6 +551,9 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
tbl = RHASH_TBL(rest);
for (i=0; i<argc; i++) {
VALUE mem = rb_to_symbol(argv[i]);
if (rb_is_attrset_sym(mem)) {
rb_raise(rb_eArgError, "invalid struct member: %"PRIsVALUE, mem);
}
if (st_insert(tbl, mem, Qtrue)) {
rb_raise(rb_eArgError, "duplicate member: %"PRIsVALUE, mem);
}

View file

@ -60,6 +60,10 @@ module TestStruct
assert_equal(1, o.a)
end
def test_attrset_id
assert_raise(ArgumentError) { Struct.new(:x=) }
end
def test_members
klass = @Struct.new(:a)
o = klass.new(1)