From 516ec5965ab03c1a4c3c192160387ea8b2c75bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 26 Sep 2023 14:10:16 +0200 Subject: [PATCH] IBX-6640: Fixed infinite loop when Normalizer returns an object --- .../Generator/Xml/FieldTypeHashGenerator.php | 5 +++++ .../Generator/FieldTypeHashGeneratorBaseTest.php | 14 ++++++++++++++ ...atorTest__testGenerateObjectUsingNormalizer.out | 1 + ...atorTest__testGenerateObjectUsingNormalizer.out | 2 ++ 4 files changed, 22 insertions(+) create mode 100644 tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out create mode 100644 tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out diff --git a/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php b/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php index 739a2d3c..cde95967 100644 --- a/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php +++ b/src/lib/Output/Generator/Xml/FieldTypeHashGenerator.php @@ -255,6 +255,11 @@ private function generateObjectValue(object $value, \XmlWriter $writer, ?string ]); $value = null; } + + if (is_object($value)) { + return; + } + $this->generateValue($writer, $value, $key, $elementName); } } diff --git a/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php b/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php index 8d71ca8d..79c03596 100644 --- a/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php +++ b/tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php @@ -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)[]; diff --git a/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out b/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out new file mode 100644 index 00000000..024c4fdf --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/Json_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out @@ -0,0 +1 @@ +{"Field":{"fieldValue":{}}} \ No newline at end of file diff --git a/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out b/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out new file mode 100644 index 00000000..bc8ead89 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/Xml_FieldTypeHashGeneratorTest__testGenerateObjectUsingNormalizer.out @@ -0,0 +1,2 @@ + +