From bdbf264771d2e9180842f9189a8281e3a73b1263 Mon Sep 17 00:00:00 2001 From: Geert Weening Date: Tue, 11 Nov 2014 11:51:12 -0800 Subject: [PATCH] [FIX] support string '0' being interpreted as XRP --- src/js/ripple/currency.js | 2 +- test/currency-test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/js/ripple/currency.js b/src/js/ripple/currency.js index cdcc1fab..859ee140 100644 --- a/src/js/ripple/currency.js +++ b/src/js/ripple/currency.js @@ -68,7 +68,7 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) { case 'string': // if an empty string is given, fall back to XRP - if (!j) { + if (!j || j === '0') { this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO); break; } diff --git a/test/currency-test.js b/test/currency-test.js index 03471988..e95b0285 100644 --- a/test/currency-test.js +++ b/test/currency-test.js @@ -198,6 +198,16 @@ describe('Currency', function() { cur2 = currency.from_json(cur); assert.strictEqual(cur.to_json(), cur2.to_json()); }); + it('should parse json 0', function() { + var cur = currency.from_json(0); + assert.strictEqual(cur.to_json(), 'XRP'); + assert.strictEqual(cur.get_iso(), 'XRP'); + }); + it('should parse json 0', function() { + var cur = currency.from_json('0'); + assert.strictEqual(cur.to_json(), 'XRP'); + assert.strictEqual(cur.get_iso(), 'XRP'); + }); }); describe('is_valid', function() {