mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 20:55:48 +00:00
[FIX] support string '0' being interpreted as XRP
This commit is contained in:
@@ -68,7 +68,7 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
|||||||
case 'string':
|
case 'string':
|
||||||
|
|
||||||
// if an empty string is given, fall back to XRP
|
// 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);
|
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,6 +198,16 @@ describe('Currency', function() {
|
|||||||
cur2 = currency.from_json(cur);
|
cur2 = currency.from_json(cur);
|
||||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
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() {
|
describe('is_valid', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user