Permalink
Browse files

check length of array content

  • Loading branch information...
rkh committed May 15, 2011
1 parent 6d30764 commit 095883272cafc69490eb0a91329069dd9cde0380
Showing with 7 additions and 0 deletions.
  1. +1 −0 lib/otnetstring.rb
  2. +6 −0 spec/otnetstring_spec.rb
View
@@ -28,6 +28,7 @@ def self.parse(io)
array = []
start = io.pos
array << parse(io) while io.pos - start < length
+ raise Error, 'Nested element longer than container' if io.pos - start != length
byte == "{" ? Hash[*array] : array
else
raise Error, "Unknown type '#{byte}'"
View
@@ -77,6 +77,12 @@
OTNetstring.parse('3?123')
}.should raise_error(OTNetstring::Error, "Unknown type '?'")
end
+
+ it 'raises and error if length of elements does not match array length' do
+ lambda {
+ OTNetstring.parse('4{5,12345')
+ }.should raise_error(OTNetstring::Error, "Nested element longer than container")
+ end
end
context "encoding" do

0 comments on commit 0958832

Please sign in to comment.