From 12116ea4f4ad2d3cc32b88ad724c2cda97ba165c Mon Sep 17 00:00:00 2001 From: adlawson Date: Tue, 16 Feb 2016 14:45:41 +0000 Subject: [PATCH 1/3] Update json_decode to accept empty string in PHP7 Previous versions of PHP allowed empty strings, but support seems to have been dropped in jsond. --- src/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 3f08f8a..07fb5a3 100644 --- a/src/functions.php +++ b/src/functions.php @@ -43,8 +43,8 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0) JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found', JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded', - ]; - $data = \json_decode($json, $assoc, $depth, $options); + ]; + $data = \json_decode($json == "" ? "{}" : $json, $assoc, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) { $last = json_last_error(); From 9666d1581bbcb5b72c8b6d18e375d072853ef7f3 Mon Sep 17 00:00:00 2001 From: adlawson Date: Tue, 16 Feb 2016 14:47:02 +0000 Subject: [PATCH 2/3] Remove PHP7 from allowed failures list in Travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9c49f3e..c5dbdff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ php: matrix: allow_failures: - - php: 7 - php: hhvm fast_finish: true From c943f3e7c02c6e26fb9d7857b779110660021b8a Mon Sep 17 00:00:00 2001 From: adlawson Date: Tue, 16 Feb 2016 15:02:27 +0000 Subject: [PATCH 3/3] Add comment explaining patch --- src/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/functions.php b/src/functions.php index 07fb5a3..da97420 100644 --- a/src/functions.php +++ b/src/functions.php @@ -44,6 +44,8 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0) JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded', ]; + + // Patched support for decoding empty strings for PHP 7+ $data = \json_decode($json == "" ? "{}" : $json, $assoc, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) {