Permalink
Browse files

check lenght of nil

  • Loading branch information...
1 parent 0958832 commit 261714eabdc74a5fad63f5eee9451dfb30816ce4 @rkh committed May 15, 2011
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/otnetstring.rb
  2. +6 −0 spec/otnetstring_spec.rb
View
@@ -22,7 +22,7 @@ def self.parse(io)
case byte
when '#' then Integer io.read(length)
when ',' then io.read(length)
- when '~' then nil
+ when '~' then raise Error, "nil has length of 0, #{length} given" unless length == 0
when '!' then io.read(length) == 'true'
when '[', '{'
array = []
View
@@ -78,6 +78,12 @@
}.should raise_error(OTNetstring::Error, "Unknown type '?'")
end
+ it 'raises and error if length nil is not 0' do
+ lambda {
+ OTNetstring.parse('1~x')
+ }.should raise_error(OTNetstring::Error, "nil has length of 0, 1 given")
+ end
+
it 'raises and error if length of elements does not match array length' do
lambda {
OTNetstring.parse('4{5,12345')

1 comment on commit 261714e

Owner

rkh commented on 261714e May 15, 2011

s/lenght/length/

Please sign in to comment.