Skip to content

Commit

Permalink
Raise an error if length is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 15, 2011
1 parent 79b7a07 commit 7fdae39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/otnetstring.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def self.parse(io)


if length.size > 9 if length.size > 9
raise Error, "#{length} is longer than 9 digits" raise Error, "#{length} is longer than 9 digits"
elsif length !~ /\d+/
raise Error, "Expected '#{byte}' to be a digit"
end end
length = Integer(length) length = Integer(length)


Expand Down
6 changes: 6 additions & 0 deletions spec/otnetstring_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
OTNetstring.parse('4!true!').should == true OTNetstring.parse('4!true!').should == true
end end


it "raises an error if length is missing" do
lambda {
OTNetstring.parse('#123')
}.should raise_error(OTNetstring::Error, "Expected '#' to be a digit")
end

it "raises an error if length is longer than 9 digits" do it "raises an error if length is longer than 9 digits" do
lambda { lambda {
OTNetstring.parse('9' * 10 + ',') OTNetstring.parse('9' * 10 + ',')
Expand Down

0 comments on commit 7fdae39

Please sign in to comment.