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

Allow dictionary values to be null #7

Merged
merged 1 commit into from
Jun 21, 2011
Merged
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
1 change: 0 additions & 1 deletion lib/tnetstring.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def self.parse_pair(data) # :nodoc:
assert key.kind_of?(String) || key.kind_of?(Symbol), "Dictionary keys must be Strings or Symbols" assert key.kind_of?(String) || key.kind_of?(Symbol), "Dictionary keys must be Strings or Symbols"
assert extra, "Unbalanced dictionary store" assert extra, "Unbalanced dictionary store"
value, extra = parse(extra) value, extra = parse(extra)
assert value, "Got an invalid value, null not allowed"


[key, value, extra] [key, value, extra]
end end
Expand Down
4 changes: 4 additions & 0 deletions spec/tnetstring_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
TNetstring.parse('0:~')[0].should == nil TNetstring.parse('0:~')[0].should == nil
end end


it "parses a dictionary with a null value" do
TNetstring.parse("9:3:key,0:~}")[0].should == {"key" => nil}
end

it "raises on a lengthy null" do it "raises on a lengthy null" do
expect { TNetstring.parse('1:x~')[0] }.to raise_error(TNetstring::ProcessError) expect { TNetstring.parse('1:x~')[0] }.to raise_error(TNetstring::ProcessError)
end end
Expand Down