Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions library/Zend/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions tests/Zend/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(''));
}

}

/**
Expand Down