Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Raise an error if length is missing

  • Loading branch information...
commit 7fdae390ad34ad54e305e0f002d356a88dc8604c 1 parent 79b7a07
Joshua Peek josh authored

Showing 2 changed files with 8 additions and 0 deletions. Show diff stats Hide diff stats

  1. +2 0  lib/otnetstring.rb
  2. +6 0 spec/otnetstring_spec.rb
2  lib/otnetstring.rb
@@ -14,6 +14,8 @@ def self.parse(io)
14 14
15 15 if length.size > 9
16 16 raise Error, "#{length} is longer than 9 digits"
  17 + elsif length !~ /\d+/
  18 + raise Error, "Expected '#{byte}' to be a digit"
17 19 end
18 20 length = Integer(length)
19 21
6 spec/otnetstring_spec.rb
@@ -60,6 +60,12 @@
60 60 OTNetstring.parse('4!true!').should == true
61 61 end
62 62
  63 + it "raises an error if length is missing" do
  64 + lambda {
  65 + OTNetstring.parse('#123')
  66 + }.should raise_error(OTNetstring::Error, "Expected '#' to be a digit")
  67 + end
  68 +
63 69 it "raises an error if length is longer than 9 digits" do
64 70 lambda {
65 71 OTNetstring.parse('9' * 10 + ',')

0 comments on commit 7fdae39

Please sign in to comment.
Something went wrong with that request. Please try again.