From 2a67ebb4bf0ae2c4468561ac7f7e5bac23b57065 Mon Sep 17 00:00:00 2001 From: Sergey Scheglov Date: Wed, 8 Jun 2022 01:13:30 +0700 Subject: [PATCH 1/2] Added test for .toString(2..36) --- test/utils-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/utils-test.js b/test/utils-test.js index 6ff1f93..e65f987 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -15,6 +15,14 @@ describe('BN.js/Utils', function () { } }); }); + describe('negative empty value', function () { + it('should have the same output as the input', function () { + var a = new BN('-'); + for(var i = 2; i <= 36; i++) { + assert.equal(a.toString(i), '-'); + } + }); + }); describe('binary padding', function () { it('should have a length of 256', function () { var a = new BN(0); From 5adf9e02fbddc51b67b42b482050b98355e59439 Mon Sep 17 00:00:00 2001 From: Sergey Scheglov Date: Wed, 8 Jun 2022 01:16:05 +0700 Subject: [PATCH 2/2] Fix endless cycle .toString(2..15&17..32) --- lib/bn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bn.js b/lib/bn.js index adecc94..77b6e57 100644 --- a/lib/bn.js +++ b/lib/bn.js @@ -511,7 +511,7 @@ out = ''; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { + while (!c.isZero() && c.length !== 0) { var r = c.modrn(groupBase).toString(base); c = c.idivn(groupBase);