diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index e958a831c5..b570acbd95 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -419,7 +419,7 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append_ld(dc, RARRAY_LEN(obj)); if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, ELTS_SHARED)) dump_append(dc, ", \"shared\":true"); - if (RARRAY_LEN(obj) > 0 && FL_TEST(obj, RARRAY_EMBED_FLAG)) + if (FL_TEST(obj, RARRAY_EMBED_FLAG)) dump_append(dc, ", \"embedded\":true"); break; diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 781fb5b3c2..c9ed62f6f6 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -307,6 +307,28 @@ class TestObjSpace < Test::Unit::TestCase JSON.parse(info) if defined?(JSON) end + def test_dump_array + # Empty array + info = ObjectSpace.dump([]) + assert_include(info, '"length":0, "embedded":true') + assert_not_include(info, '"shared":true') + + # Non-embed array + arr = (1..10).to_a + info = ObjectSpace.dump(arr) + assert_include(info, '"length":10') + assert_not_include(info, '"embedded":true') + assert_not_include(info, '"shared":true') + + # Shared array + arr1 = (1..10).to_a + arr = [] + arr.replace(arr1) + info = ObjectSpace.dump(arr) + assert_include(info, '"length":10, "shared":true') + assert_not_include(info, '"embedded":true') + end + def test_dump_control_char assert_include(ObjectSpace.dump("\x0f"), '"value":"\u000f"') assert_include(ObjectSpace.dump("\C-?"), '"value":"\u007f"')