Skip to content

Commit

Permalink
Merge pull request #431 from tmilos/erroneous_unserialize
Browse files Browse the repository at this point in the history
Erroneous data format for unserializing #430
  • Loading branch information
schmittjoh committed Apr 17, 2015
2 parents e619ca4 + 5efdc34 commit 8fc5eb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"jms/metadata": "~1.1",
"jms/parser-lib": "1.*",
"phpcollection/phpcollection": "~0.1",
"doctrine/annotations": "1.*"
"doctrine/annotations": "1.*",
"doctrine/instantiator": "~1.0.3"
},
"suggest": {
"symfony/yaml": "Required if you'd like to serialize data to YAML format."
Expand Down
18 changes: 17 additions & 1 deletion src/JMS/Serializer/Construction/UnserializeObjectConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,30 @@

namespace JMS\Serializer\Construction;

use Doctrine\Instantiator\Instantiator;
use JMS\Serializer\VisitorInterface;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\DeserializationContext;

class UnserializeObjectConstructor implements ObjectConstructorInterface
{
/** @var Instantiator */
private $instantiator;

public function construct(VisitorInterface $visitor, ClassMetadata $metadata, $data, array $type, DeserializationContext $context)
{
return unserialize(sprintf('O:%d:"%s":0:{}', strlen($metadata->name), $metadata->name));
return $this->getInstantiator()->instantiate($metadata->name);
}

/**
* @return Instantiator
*/
private function getInstantiator()
{
if (null == $this->instantiator) {
$this->instantiator = new Instantiator();
}

return $this->instantiator;
}
}

0 comments on commit 8fc5eb9

Please sign in to comment.