From 8a0098d8412e7759d9cda82057f41a6dc25a0fe6 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Wed, 15 Apr 2026 14:24:45 +0200 Subject: [PATCH 1/3] IBX-11610: Images with width="" or height="" in xml definition will cause crash --- src/lib/FieldType/Image/Type.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/FieldType/Image/Type.php b/src/lib/FieldType/Image/Type.php index 90fa8fb0cc..655aa2fc4f 100644 --- a/src/lib/FieldType/Image/Type.php +++ b/src/lib/FieldType/Image/Type.php @@ -438,12 +438,12 @@ public function fromPersistenceValue(FieldValue $fieldValue) 'imageId' => (isset($fieldValue->data['imageId']) ? $fieldValue->data['imageId'] : null), - 'width' => (isset($fieldValue->data['width']) + 'width' => ($fieldValue->data['width'] ?? '') !== '' ? $fieldValue->data['width'] - : null), - 'height' => (isset($fieldValue->data['height']) + : null, + 'height' => ($fieldValue->data['height'] ?? '') !== '' ? $fieldValue->data['height'] - : null), + : null, 'additionalData' => $fieldValue->data['additionalData'] ?? [], 'mime' => $fieldValue->data['mime'] ?? null, ] From 9aff5e6078c955b659dc7199bd90ed53572ab33d Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 3 Jul 2026 11:34:23 +0200 Subject: [PATCH 2/3] Write tests for IBX-11610: Images with width= or height= in xml definition will cause crash --- .../Core/Imagine/AliasGeneratorTest.php | 51 +++++++++++++++++ tests/lib/FieldType/ImageTest.php | 57 +++++++++++++++++++ .../Converter/ImageConverterTest.php | 23 ++++++++ 3 files changed, 131 insertions(+) diff --git a/tests/bundle/Core/Imagine/AliasGeneratorTest.php b/tests/bundle/Core/Imagine/AliasGeneratorTest.php index 129686cfe0..d701acb302 100644 --- a/tests/bundle/Core/Imagine/AliasGeneratorTest.php +++ b/tests/bundle/Core/Imagine/AliasGeneratorTest.php @@ -247,6 +247,57 @@ public function testGetVariationOriginal(): void ); } + public function testGetVariationOriginalWithNullWidthAndHeight(): void + { + $originalPath = 'foo/bar/image.jpg'; + $variationName = 'original'; + $imageId = '123-45'; + $imageValue = new ImageValue( + [ + 'id' => $originalPath, + 'imageId' => $imageId, + 'width' => null, + 'height' => null, + 'fileSize' => 1024, + 'mime' => 'image/jpeg', + ] + ); + $field = new Field([ + 'value' => $imageValue, + 'fieldDefIdentifier' => 'image_field', + ]); + $expectedUrl = 'http://localhost/foo/bar/image.jpg'; + + $this->ioResolver + ->expects(self::once()) + ->method('resolve') + ->with($originalPath, $variationName) + ->will(self::returnValue($expectedUrl)); + + $expected = new ImageVariation( + [ + 'name' => $variationName, + 'fileName' => 'image.jpg', + 'dirPath' => 'http://localhost/foo/bar', + 'uri' => $expectedUrl, + 'imageId' => $imageId, + 'height' => null, + 'width' => null, + 'fileSize' => 1024, + 'mimeType' => 'image/jpeg', + ] + ); + + self::assertEquals( + $expected, + $this->aliasGenerator->getVariation( + $field, + new VersionInfo(), + $variationName + ) + ); + } + /** * Test obtaining Image Variation that hasn't been stored yet and has multiple references. * diff --git a/tests/lib/FieldType/ImageTest.php b/tests/lib/FieldType/ImageTest.php index 92ecb5434a..f806ea6fa3 100644 --- a/tests/lib/FieldType/ImageTest.php +++ b/tests/lib/FieldType/ImageTest.php @@ -8,6 +8,7 @@ namespace Ibexa\Tests\Core\FieldType; use Ibexa\Contracts\Core\IO\MimeTypeDetector; +use Ibexa\Contracts\Core\Persistence\Content\FieldValue; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\FieldType\Image\Type as ImageType; @@ -347,6 +348,62 @@ public function provideInputForFromHash(): iterable ]; } + /** + * @phpstan-return iterable, mixed, mixed}> + */ + public function provideDataForFromPersistenceValue(): iterable + { + yield 'width and height as empty string are converted to null' => [ + [ + 'width' => '', + 'height' => '', + ], + null, + null, + ]; + + yield 'width and height as zero are preserved' => [ + [ + 'width' => 0, + 'height' => '0', + ], + 0, + '0', + ]; + + yield 'width and height as valid values are preserved' => [ + [ + 'width' => 100, + 'height' => '200', + ], + 100, + '200', + ]; + + yield 'missing width and height keys default to null' => [ + [], + null, + null, + ]; + } + + /** + * @param array $data + * + * @dataProvider provideDataForFromPersistenceValue + */ + public function testFromPersistenceValue(array $data, mixed $expectedWidth, mixed $expectedHeight): void + { + $fieldType = $this->getFieldTypeUnderTest(); + + $fieldValue = new FieldValue(['data' => $data]); + $result = $fieldType->fromPersistenceValue($fieldValue); + + self::assertInstanceOf(ImageValue::class, $result); + self::assertSame($expectedWidth, $result->width); + self::assertSame($expectedHeight, $result->height); + } + protected function provideFieldTypeIdentifier(): string { return 'ibexa_image'; diff --git a/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php b/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php index 7d25304b03..21c08e4b44 100644 --- a/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php +++ b/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php @@ -223,6 +223,29 @@ public function xmlToFieldValueProvider(): array ], ]), ], + 'with_empty_width_and_height' => [ +<<< XML + + + + + +XML, + new FieldValue([ + 'data' => [ + 'width' => '', + 'height' => '', + 'alternativeText' => 'test', + 'mime' => 'image/png', + 'id' => 1, + 'fileName' => 'ibexa_fav.png', + 'additionalData' => [], + ], + ]), + ], ]; } } From f292ccc7740f5d3fa970e37d5a1f589126aa2044 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 3 Jul 2026 16:25:22 +0200 Subject: [PATCH 3/3] Fixed indention for HEREDOCs in ImageConverterTest --- .../Converter/ImageConverterTest.php | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php b/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php index 21c08e4b44..63f2e0f41f 100644 --- a/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php +++ b/tests/lib/Persistence/Legacy/FieldValue/Converter/ImageConverterTest.php @@ -93,16 +93,16 @@ public function fieldValueToXmlProvider(): array ], ]), <<< XML - - - - - 50100John Smith - -XML, + + + + + 50100John Smith + + XML, ], 'without_additional_data_stored' => [ new FieldValue([ @@ -118,16 +118,16 @@ public function fieldValueToXmlProvider(): array ], ]), <<< XML - - - - - - -XML, + + + + + + + XML, ], ]; } @@ -169,21 +169,21 @@ public function xmlToFieldValueProvider(): array return [ 'with_additional_data' => [ -<<< XML - - - - - - 50 - 100 - John Smith - - -XML, + <<< XML + + + + + + 50 + 100 + John Smith + + + XML, new FieldValue([ 'data' => [ 'width' => '100', @@ -201,16 +201,16 @@ public function xmlToFieldValueProvider(): array ]), ], 'without_additional_data_stored' => [ -<<< XML - - - - - -XML, + <<< XML + + + + + + XML, new FieldValue([ 'data' => [ 'width' => '100', @@ -224,16 +224,16 @@ public function xmlToFieldValueProvider(): array ]), ], 'with_empty_width_and_height' => [ -<<< XML - - - - - -XML, + <<< XML + + + + + + XML, new FieldValue([ 'data' => [ 'width' => '',