Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default hash tokenizing and parsing. #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
=== 2.1 / 2017-05-16

* Bug fix
* Tokenize and parse :default_hash

=== 2.0 / ??

* API Change
Expand Down
2 changes: 1 addition & 1 deletion lib/marshal/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def initialize consumed, requested
##
# Version of Marshal::Structure you are using

VERSION = '2.0'
VERSION = '2.1'

##
# The Marshal stream
Expand Down
4 changes: 1 addition & 3 deletions lib/marshal/structure/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
3 changes: 2 additions & 1 deletion lib/marshal/structure/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
3 changes: 1 addition & 2 deletions lib/marshal/structure/tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_marshal_structure_allocation_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion test/test_marshal_structure_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions test/test_marshal_structure_tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down