ruby-changes:26496
From: glass <ko1@a...>
Date: Sat, 22 Dec 2012 11:53:00 +0900 (JST)
Subject: [ruby-changes:26496] glass:r38547 (trunk): * struct.c (make_struct): remove junk ID check to allow members who
glass 2012-12-22 11:52:48 +0900 (Sat, 22 Dec 2012) New Revision: 38547 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38547 Log: * struct.c (make_struct): remove junk ID check to allow members who have junk name like "foo\000". * test/ruby/test_struct.rb: Test for above. [Bug #7575] [ruby-dev:46750] Modified files: trunk/ChangeLog trunk/struct.c trunk/test/ruby/test_struct.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38546) +++ ChangeLog (revision 38547) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Dec 22 11:30:21 2012 Masaki Matsushita <glass.saga@g...> + + * struct.c (make_struct): remove junk ID check to allow members who + have junk name like "foo\000". + * test/ruby/test_struct.rb: Test for above. + [Bug #7575] [ruby-dev:46750] + Sat Dec 22 05:34:54 2012 Eric Hodel <drbrain@s...> * lib/net/http.rb: Requests may be created with a URI which sets the Index: struct.c =================================================================== --- struct.c (revision 38546) +++ struct.c (revision 38547) @@ -207,15 +207,13 @@ make_struct(VALUE name, VALUE members, V https://github.com/ruby/ruby/blob/trunk/struct.c#L207 len = RARRAY_LEN(members); for (i=0; i< len; i++) { ID id = SYM2ID(ptr_members[i]); - if (rb_is_local_id(id) || rb_is_const_id(id)) { - if (i < N_REF_FUNC) { - rb_define_method_id(nstr, id, ref_func[i], 0); - } - else { - rb_define_method_id(nstr, id, rb_struct_ref, 0); - } - rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1); + if (i < N_REF_FUNC) { + rb_define_method_id(nstr, id, ref_func[i], 0); } + else { + rb_define_method_id(nstr, id, rb_struct_ref, 0); + } + rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1); } return nstr; Index: test/ruby/test_struct.rb =================================================================== --- test/ruby/test_struct.rb (revision 38546) +++ test/ruby/test_struct.rb (revision 38547) @@ -227,6 +227,13 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L227 assert_equal("#<struct Struct::R\u{e9}sum\u{e9} r\u{e9}sum\u{e9}=42>", a.inspect, '[ruby-core:24849]') end + def test_junk + struct_test = Struct.new("Foo", "a\000") + o = struct_test.new(1) + assert_equal(1, o.send("a\000")) + Struct.instance_eval { remove_const(:Foo) } + end + def test_comparison_when_recursive klass1 = Struct.new(:a, :b, :c) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/