diff --git a/ChangeLog b/ChangeLog index 1c17105ac0..639f5b0685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jun 13 09:58:26 2009 Nobuyoshi Nakada + + * marshal.c (r_ivar): should not set internal encoding ivar as an + ordinary ivar. [ruby-dev:38596] + Sat Jun 13 07:08:40 2009 Nobuyoshi Nakada * vm_eval.c (rb_f_local_variables): now returns symbols. a patch from diff --git a/marshal.c b/marshal.c index 807a0335a2..d67168db97 100644 --- a/marshal.c +++ b/marshal.c @@ -1159,14 +1159,14 @@ r_ivar(VALUE obj, struct load_arg *arg) len = r_long(arg); if (len > 0) { - while (len--) { + do { ID id = r_symbol(arg); VALUE val = r_object(arg); if (id == rb_id_encoding()) { int idx = rb_enc_find_index(StringValueCStr(val)); if (idx > 0) rb_enc_associate_index(obj, idx); } - if (id == rb_intern("E")) { + else if (id == rb_intern("E")) { if (val == Qfalse) rb_enc_associate_index(obj, rb_usascii_encindex()); else if (val == Qtrue) rb_enc_associate_index(obj, rb_utf8_encindex()); /* bogus ignore */ @@ -1174,7 +1174,7 @@ r_ivar(VALUE obj, struct load_arg *arg) else { rb_ivar_set(obj, id, val); } - } + } while (--len > 0); } } diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index 6e442b564b..6edad2418f 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -60,4 +60,12 @@ class TestEncoding < Test::Unit::TestCase assert_instance_of(String, v) end end + + def test_marshal + str = "".force_encoding("EUC-JP") + str2 = Marshal.load(Marshal.dump(str)) + assert_equal(str, str2) + str2 = Marshal.load(Marshal.dump(str2)) + assert_equal(str, str2, '[ruby-dev:38596]') + end end