Skip to content

Commit

Permalink
IBX-6640: Fixed infinite loop when Normalizer returns an object
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p authored Sep 27, 2023
1 parent 094073f commit 108a074
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/Output/Generator/Json/FieldTypeHashGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ private function generateObjectValue($parent, object $value)
$value = null;
}

return $this->generateValue($parent, $value);
if (is_array($value)) {
return $this->generateArrayValue($parent, $value);
}

return $value;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ private function generateObjectValue(object $value, \XmlWriter $writer, ?string
]);
$value = null;
}

if (is_object($value)) {
$this->generateNullValue($writer, $key, $elementName);

return;
}

$this->generateValue($writer, $value, $key, $elementName);
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,20 @@ public function testGenerateUsingNormalizer(): void
$this->assertSerializationSame(__FUNCTION__);
}

public function testGenerateObjectUsingNormalizer(): void
{
$object = (object)[];
$this->getNormalizer()
->expects(self::once())
->method('normalize')
->with(self::identicalTo($object))
->willReturnArgument(0);

$this->getGenerator()->generateFieldTypeHash('fieldValue', $object);

$this->assertSerializationSame(__FUNCTION__);
}

public function testGenerateWithMissingNormalizer(): void
{
$object = (object)[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Field":{"fieldValue":{}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Field>
<fieldValue/>
</Field>

0 comments on commit 108a074

Please sign in to comment.