Permalink
Browse files

Gracefully deals with bad input. Thanks to isnotvalid on Github.

  • Loading branch information...
1 parent e084dac commit 6e7ffee416046b664a5e591ab91ea91d409397a4 @dougal committed Nov 27, 2009
Showing with 10 additions and 0 deletions.
  1. +3 −0 CHANGELOG
  2. +1 −0 lib/base58.rb
  3. +6 −0 test/test_base58.rb
View
@@ -1,3 +1,6 @@
+= 0.0.4
+- Gracefully deals with bad input. Thanks to isnotvalid on Github.
+
= 0.0.3
- Removed accidental dependencies.
View
@@ -19,6 +19,7 @@ def self.base58_to_int(base58_val)
# Converts a base10 integer to a base58 string.
def self.int_to_base58(int_val)
+ raise ArgumentError, 'Value passed is not an Integer.' unless int_val.is_a?(Integer)
base58_val = ''
while(int_val >= BASE)
mod = int_val % BASE
View
@@ -515,4 +515,10 @@ def test_base58_to_int
assert_equal expected, Base58.base58_to_int(base_58)
end
end
+
+ def test_string_instead_of_int
+ e = assert_raise(ArgumentError) { Base58.int_to_base58('3470432637') }
+ assert_equal 'Value passed is not an Integer.', e.message
+ end
+
end

0 comments on commit 6e7ffee

Please sign in to comment.