diff --git a/jsonparse.js b/jsonparse.js index 3991060..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 { 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]'); });