diff --git a/History.txt b/History.txt index ebe93bf..43f2b67 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,8 @@ +=== 2.1 / 2017-05-16 + +* Bug fix + * Tokenize and parse :default_hash + === 2.0 / ?? * API Change diff --git a/lib/marshal/structure.rb b/lib/marshal/structure.rb index acbcda5..58e9033 100644 --- a/lib/marshal/structure.rb +++ b/lib/marshal/structure.rb @@ -62,7 +62,7 @@ def initialize consumed, requested ## # Version of Marshal::Structure you are using - VERSION = '2.0' + VERSION = '2.1' ## # The Marshal stream diff --git a/lib/marshal/structure/parser.rb b/lib/marshal/structure/parser.rb index 7474aee..b2ac156 100644 --- a/lib/marshal/structure/parser.rb +++ b/lib/marshal/structure/parser.rb @@ -159,9 +159,7 @@ def parse_hash # Creates the body of a +:hash_def+ object def parse_hash_def - ref, hash = parse_hash - - [ref, hash, parse] + [*parse_hash, parse] end ## diff --git a/lib/marshal/structure/test_case.rb b/lib/marshal/structure/test_case.rb index 27d5ea9..d47e957 100644 --- a/lib/marshal/structure/test_case.rb +++ b/lib/marshal/structure/test_case.rb @@ -60,7 +60,8 @@ class Marshal::Structure::TestCase < MiniTest::Unit::TestCase EVERYTHING = "\004\b{\006:\006a[\031c\006Bm\006C\"\006d/\006e\000i\006" \ "f\0322.2999999999999998\000ff" \ - "l+\n\000\000\000\000\000\000\000\000\001\0000TF}\000i\000" \ + "l+\n\000\000\000\000\000\000\000\000\001\0000TF" \ + "}\ai\x06i\aTFi\x02\x94\x01" \ "S:\006S\006:\006fi\000o:\vObject\000@\017" \ "U:\006M\"\021marshal_dump" \ "Iu:\006U\n_dump\006" \ diff --git a/lib/marshal/structure/tokenizer.rb b/lib/marshal/structure/tokenizer.rb index 216182c..13526c5 100644 --- a/lib/marshal/structure/tokenizer.rb +++ b/lib/marshal/structure/tokenizer.rb @@ -368,8 +368,7 @@ def tokenize_data # :nodoc: def tokenize_hash_default # :nodoc: size = long - @state.push :any - @state.push size * 2 if size > 0 + @state.concat Array.new(size * 2 + 1, :any) size end diff --git a/test/test_marshal_structure_allocation_counter.rb b/test/test_marshal_structure_allocation_counter.rb index c9430b4..6d40ddf 100644 --- a/test/test_marshal_structure_allocation_counter.rb +++ b/test/test_marshal_structure_allocation_counter.rb @@ -63,7 +63,7 @@ def test_count_hash end def test_count_hash_default - count = count_allocations "\x04\x08}\x00i\x06" + count = count_allocations "\x04\b}\ai\x06i\aTFi\x02\x94\x01" assert_equal 1, count end diff --git a/test/test_marshal_structure_parser.rb b/test/test_marshal_structure_parser.rb index e1c5279..a747c13 100644 --- a/test/test_marshal_structure_parser.rb +++ b/test/test_marshal_structure_parser.rb @@ -26,7 +26,10 @@ def test_parse :nil, :true, :false, - [:hash_default, 8, 0, [:fixnum, 0]], + [:hash_default, 8, 2, + [:fixnum, 1], [:fixnum, 2], + :true, :false, + [:fixnum, 404]], [:struct, 9, [:symbol, 1, "S"], 1, [:symbol, 2, "f"], [:fixnum, 0]], [:object, 10, [:symbol, 3, "Object"], [0]], [:link, 10], diff --git a/test/test_marshal_structure_tokenizer.rb b/test/test_marshal_structure_tokenizer.rb index 749728d..e0a6d23 100644 --- a/test/test_marshal_structure_tokenizer.rb +++ b/test/test_marshal_structure_tokenizer.rb @@ -164,9 +164,9 @@ def test_tokens_hash end def test_tokens_hash_default - ms = @MST.new "\x04\x08}\x00i\x06" + ms = @MST.new "\x04\b}\ai\x06i\aTFi\x02\x94\x01" - assert_equal [:hash_default, 0, :fixnum, 1], ms.tokens.to_a + assert_equal [:hash_default, 2, :fixnum, 1, :fixnum, 2, :true, :false, :fixnum, 404], ms.tokens.to_a end def test_tokens_instance_variables