From dd831c4862918fd7a6832434b20e275358712978 Mon Sep 17 00:00:00 2001 From: mmikhalko <42734944+mmikhalko@users.noreply.github.com> Date: Mon, 16 Sep 2019 11:53:27 +0300 Subject: [PATCH 1/3] Fix a negative big int number parsing --- jsonparse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonparse.js b/jsonparse.js index 3991060..85dbcbf 100644 --- a/jsonparse.js +++ b/jsonparse.js @@ -267,7 +267,7 @@ proto.write = function (buffer) { return this.charError(buffer, i); } - if ((this.string.match(/[0-9]+/) == this.string) && (result.toString() != this.string)) { + if ((this.string.match(/-?[0-9]+/) == this.string) && (result.toString() != this.string)) { // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number this.onToken(STRING, this.string); } else { From d6d32b0a44cc6fc2a96c971097262a6860809b2f Mon Sep 17 00:00:00 2001 From: mmikhalko <42734944+mmikhalko@users.noreply.github.com> Date: Mon, 16 Sep 2019 11:56:00 +0300 Subject: [PATCH 2/3] Add test with a negative big int number --- test/primitives.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/primitives.js b/test/primitives.js index 33cae16..ee8a015 100644 --- a/test/primitives.js +++ b/test/primitives.js @@ -26,11 +26,13 @@ var expected = [ [ [ 0 ], 6.02e+23 ], [ [], [ 6.02e+23 ] ], [ [ 0 ], '7161093205057351174' ], - [ [], [ '7161093205057351174'] ] + [ [], [ '7161093205057351174'] ], + [ [ 0 ], '-9223372036854775808' ], + [ [], [ '-9223372036854775808'] ], ]; test('primitives', function (t) { - t.plan(25); + t.plan(27); var p = new Parser(); p.onValue = function (value) { @@ -54,4 +56,5 @@ test('primitives', function (t) { p.write('[1.0,1.1,-1.1,-1.0][-1][-0.1]'); p.write('[6.02e23]'); p.write('[7161093205057351174]'); + p.write('[-9223372036854775808]'); }); From 4ef82ca0f07d7270ec1d99cc553bc4a3d09a736e Mon Sep 17 00:00:00 2001 From: Mykola Date: Wed, 25 Sep 2019 12:52:04 +0300 Subject: [PATCH 3/3] Use test instead of match --- jsonparse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonparse.js b/jsonparse.js index 85dbcbf..278a800 100644 --- a/jsonparse.js +++ b/jsonparse.js @@ -267,7 +267,7 @@ proto.write = function (buffer) { return this.charError(buffer, i); } - if ((this.string.match(/-?[0-9]+/) == this.string) && (result.toString() != this.string)) { + if (/^-?[0-9]+$/.test(this.string) && (result.toString() != this.string)) { // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number this.onToken(STRING, this.string); } else {