From 47ae862ae9128c35fdcebd5ea3e5117b007fd40d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 28 May 2014 13:29:01 +1000 Subject: [PATCH] base58: fix missing exceptions --- src/base58.js | 7 ++++++- test/base58.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/base58.js b/src/base58.js index 588ac84..5b21538 100644 --- a/src/base58.js +++ b/src/base58.js @@ -5,6 +5,7 @@ // Merged Buffer refactorings from base58-native by Stephen Pair // Copyright (c) 2013 BitPay Inc +var assert = require('assert') var BigInteger = require('bigi') var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' @@ -46,7 +47,11 @@ function decode(string) { for (var i = 0; i < string.length; i++) { num = num.multiply(BASE) - num = num.add(ALPHABET_MAP[string.charAt(i)]) + + var figure = ALPHABET_MAP[string.charAt(i)] + assert.notEqual(figure, undefined, 'Non-base58 character') + + num = num.add(figure) } // deal with leading zeros diff --git a/test/base58.js b/test/base58.js index 603a88f..f5f2754 100644 --- a/test/base58.js +++ b/test/base58.js @@ -18,7 +18,7 @@ describe('base58', function() { it('throws on ' + f.description, function() { assert.throws(function() { base58.decode(f.string) - }) + }, /Non-base58 character/) }) }) })