Skip to content

Commit 47fc8a3

Browse files
author
Chris Raynor
committed
Merge pull request firebase#10 from firebase/fix-bigint-as-string
This fixes firebase#9 - Improve check for offending json-c implementation with m...
2 parents 718e9c7 + d6c2f29 commit 47fc8a3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Authentication/JWT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static function sign($msg, $key, $method = 'HS256')
130130
*/
131131
public static function jsonDecode($input)
132132
{
133-
if (version_compare(PHP_VERSION, '5.4.0', '>=') && defined('JSON_BIGINT_AS_STRING')) {
133+
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
134134
/* In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you to specify that large ints (like Steam
135135
* Transaction IDs) should be treated as strings, rather than the PHP default behaviour of converting them to floats.
136136
*/
@@ -140,7 +140,7 @@ public static function jsonDecode($input)
140140
* string and quote them (thus converting them to strings) before decoding, hence the preg_replace() call.
141141
*/
142142
$max_int_length = strlen((string) PHP_INT_MAX) - 1;
143-
$json_without_bigints = preg_replace('/:\s*(\d{'.$max_int_length.',})/', ': "$1"', $input);
143+
$json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input);
144144
$obj = json_decode($json_without_bigints);
145145
}
146146

0 commit comments

Comments
 (0)