Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions test/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]');
});