Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ZF-7586: Zend\Json\Decoder emits fatal error when decoding JSON string with empty key #1217

Merged
merged 1 commit into from

2 participants

@adamlundrigan

Fixes ZF-7586. SVN sync r24799

@akrabat akrabat merged commit c066aff into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 12, 2012
  1. @adamlundrigan
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 0 deletions.
  1. +3 −0  library/Zend/Json/Decoder.php
  2. +13 −0 tests/Zend/Json/JsonTest.php
View
3  library/Zend/Json/Decoder.php
@@ -223,6 +223,9 @@ protected function _decodeObject()
// Create new StdClass and populate with $members
$result = new \stdClass();
foreach ($members as $key => $value) {
+ if ($key === '') {
+ $key = '_empty_';
+ }
$result->$key = $value;
}
break;
View
13 tests/Zend/Json/JsonTest.php
@@ -847,6 +847,19 @@ public function testWillEncodeArrayOfObjectsEachWithToJsonMethod()
$this->assertEquals($expected, $json);
}
+ /**
+ * @group ZF-7586
+ */
+ public function testWillDecodeStructureWithEmptyKeyToObjectProperly()
+ {
+ Json\Json::$useBuiltinEncoderDecoder = true;
+
+ $json = '{"":"test"}';
+ $object = Json\Json::decode($json, Json\Json::TYPE_OBJECT);
+ $this->assertTrue(isset($object->_empty_));
+ $this->assertEquals('test', $object->_empty_);
+ }
+
}
/**
Something went wrong with that request. Please try again.