From 334f90b7bbfdffafa70c43e7a04d2f79fc176cfb Mon Sep 17 00:00:00 2001 From: "v.noskov" Date: Wed, 16 Mar 2016 19:54:34 +0200 Subject: [PATCH] Zend_Json::decode null or empty string throw Zend_Json_Exception on PHP7 --- library/Zend/Json.php | 3 +++ tests/Zend/JsonTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/library/Zend/Json.php b/library/Zend/Json.php index ad72eb5303..78c9ce0117 100644 --- a/library/Zend/Json.php +++ b/library/Zend/Json.php @@ -73,6 +73,9 @@ class Zend_Json */ public static function decode($encodedValue, $objectDecodeType = Zend_Json::TYPE_ARRAY) { + if (in_array($encodedValue, array(null, ''))) { + return null; + } $encodedValue = (string) $encodedValue; if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) { $decode = json_decode($encodedValue, $objectDecodeType); diff --git a/tests/Zend/JsonTest.php b/tests/Zend/JsonTest.php index 711bc65223..9916df0c74 100644 --- a/tests/Zend/JsonTest.php +++ b/tests/Zend/JsonTest.php @@ -922,6 +922,40 @@ public function testWillDecodeStructureWithEmptyKeyToObjectProperly() $this->assertEquals('test', $object->_empty_); } + /** + * Decoding null should return null + */ + public function testWillDecodeNullToNull() + { + $this->assertNull(Zend_Json::decode(null)); + } + + /** + * Decoding null should return null + */ + public function testWillDecodeWithBuiltinNullToNull() + { + Zend_Json::$useBuiltinEncoderDecoder = true; + $this->assertNull(Zend_Json::decode(null)); + } + + /** + * Decoding empty string should return null + */ + public function testWillDecodeEmptyStringToNull() + { + $this->assertNull(Zend_Json::decode('')); + } + + /** + * Decoding empty string should return null + */ + public function testWillDecodeWithBuiltinEmptyStringToNull() + { + Zend_Json::$useBuiltinEncoderDecoder = true; + $this->assertNull(Zend_Json::decode('')); + } + } /**