Skip to content

This fixes #9 - Improve check for offending json-c implementation with m... #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2014
Merged
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
4 changes: 2 additions & 2 deletions Authentication/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function sign($msg, $key, $method = 'HS256')
*/
public static function jsonDecode($input)
{
if (version_compare(PHP_VERSION, '5.4.0', '>=') && defined('JSON_BIGINT_AS_STRING')) {
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
/* In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you to specify that large ints (like Steam
* Transaction IDs) should be treated as strings, rather than the PHP default behaviour of converting them to floats.
*/
Expand All @@ -140,7 +140,7 @@ public static function jsonDecode($input)
* string and quote them (thus converting them to strings) before decoding, hence the preg_replace() call.
*/
$max_int_length = strlen((string) PHP_INT_MAX) - 1;
$json_without_bigints = preg_replace('/:\s*(\d{'.$max_int_length.',})/', ': "$1"', $input);
$json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input);
$obj = json_decode($json_without_bigints);
}

Expand Down