Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
initial attempt at decoding large integers as strings (not portable)
  • Loading branch information
Grinnz committed Oct 27, 2015
1 parent 3aa5db9 commit 5a93ac3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -7,6 +7,7 @@ use Exporter 'import';
use JSON::PP ();
use Mojo::Util;
use Scalar::Util 'blessed';
use POSIX 'LONG_MAX';

our @EXPORT_OK = qw(decode_json encode_json false from_json j to_json true);

Expand Down Expand Up @@ -191,7 +192,7 @@ sub _decode_value {
return _decode_array() if /\G\[/gc;

# Number
return 0 + $1
return ($1 > LONG_MAX) ? $1 : 0 + $1
if /\G([-]?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)/gc;

# True
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/json.t
Expand Up @@ -327,6 +327,10 @@ like encode_json({test => -sin(9**9**9)}), qr/^{"test":".*"}$/,
# "null"
is j('null'), undef, 'decode null';

# Large integers
is decode_json('123456789123456789123456789'), '123456789123456789123456789',
'decoded large integer to string';

# Errors
eval { decode_json 'test' };
like $@, qr/Malformed JSON: Expected string, array, object/, 'right error';
Expand Down

0 comments on commit 5a93ac3

Please sign in to comment.