Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7295d25

Browse files
committed
bug#35846 [Serializer] prevent method calls on null values (xabbuh)
This PR was merged into the 3.4 branch.Discussion----------[Serializer] prevent method calls on null values| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#35824| License | MIT| Doc PR |Commits-------847d6dc prevent method calls on null values
2 parents6c04266 +847d6dc commit7295d25

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎src/Symfony/Component/Serializer/Encoder/XmlEncoder.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\Serializer\Encoder;
1313

14+
useSymfony\Component\Serializer\Exception\BadMethodCallException;
1415
useSymfony\Component\Serializer\Exception\NotEncodableValueException;
1516

1617
/**
@@ -375,7 +376,7 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
375376
{
376377
$append =true;
377378

378-
if (\is_array($data) || ($datainstanceof \Traversable && !$this->serializer->supportsNormalization($data,$this->format))) {
379+
if (\is_array($data) || ($datainstanceof \Traversable &&(null ===$this->serializer ||!$this->serializer->supportsNormalization($data,$this->format)))) {
379380
foreach ($dataas$key =>$data) {
380381
//Ah this is the magic @ attribute types.
381382
if (0 ===strpos($key,'@') &&$this->isElementNameValid($attributeName =substr($key,1))) {
@@ -410,6 +411,10 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
410411
}
411412

412413
if (\is_object($data)) {
414+
if (null ===$this->serializer) {
415+
thrownewBadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.',__METHOD__));
416+
}
417+
413418
$data =$this->serializer->normalize($data,$this->format,$this->context);
414419
if (null !==$data && !is_scalar($data)) {
415420
return$this->buildXml($parentNode,$data,$xmlRootNodeName);
@@ -484,6 +489,10 @@ private function selectNodeType(\DOMNode $node, $val)
484489
}elseif ($valinstanceof \Traversable) {
485490
$this->buildXml($node,$val);
486491
}elseif (\is_object($val)) {
492+
if (null ===$this->serializer) {
493+
thrownewBadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.',__METHOD__));
494+
}
495+
487496
return$this->selectNodeType($node,$this->serializer->normalize($val,$this->format,$this->context));
488497
}elseif (is_numeric($val)) {
489498
return$this->appendText($node, (string)$val);

‎src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function denormalize($data, $type, $format = null, array $context = [])
6868
*/
6969
publicfunctionsupportsDenormalization($data,$type,$format =null/*, array $context = []*/)
7070
{
71+
if (null ===$this->serializer) {
72+
thrownewBadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used.',__METHOD__));
73+
}
74+
7175
$context =\func_num_args() >3 ?func_get_arg(3) : [];
7276

7377
return'[]' ===substr($type, -2)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp