From d724e94ba85b5aa65ef7295116a4ab3f1a4894c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ausw=C3=B6ger?= Date: Sat, 21 Oct 2023 17:41:07 +0200 Subject: [PATCH] Fix unterminated entity reference error (#101) --- CHANGELOG.md | 2 ++ src/Metadata/XmpFormat.php | 9 +++++--- tests/Metadata/XmpFormatTest.php | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b1307..4f43e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] + * Fix unterminated entity reference error. [#101] ## [1.2.0] (2023-05-30) @@ -164,6 +165,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm [0.2.0]: https://github.com/contao/image/compare/0.1.0...0.2.0 [0.1.0]: https://github.com/contao/image/commits/0.1.0 +[#101]: https://github.com/contao/image/issues/101 [#98]: https://github.com/contao/image/issues/98 [#97]: https://github.com/contao/image/issues/97 [#96]: https://github.com/contao/image/issues/96 diff --git a/src/Metadata/XmpFormat.php b/src/Metadata/XmpFormat.php index dea9b62..9d59f20 100644 --- a/src/Metadata/XmpFormat.php +++ b/src/Metadata/XmpFormat.php @@ -257,9 +257,12 @@ private function buildXmp(array $metadata): string $wrap->appendChild($bag); foreach ($values as $value) { - $bag->appendChild( - $dom->createElementNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf:li', $value) - ); + $bag + ->appendChild( + $dom->createElementNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf:li') + ) + ->appendChild($dom->createTextNode($value)) + ; } } } diff --git a/tests/Metadata/XmpFormatTest.php b/tests/Metadata/XmpFormatTest.php index cad2eda..a5742cc 100644 --- a/tests/Metadata/XmpFormatTest.php +++ b/tests/Metadata/XmpFormatTest.php @@ -202,4 +202,42 @@ public function getSerialize(): \Generator '', ]; } + + public function testSerializeValuesWithAmpersands(): void + { + $this->assertSame( + "" + .'' + .'' + .'' + .'' + .'Rights& more' + .'' + .'' + .'Creator 1&crea' + .'' + .'' + .'' + .'' + .'', + (new XmpFormat())->serialize( + new ImageMetadata([ + 'xmp' => [ + 'http://purl.org/dc/elements/1.1/' => [ + 'rights' => ['Rights', '& more'], + 'creator' => ['Creator 1', '&crea'], + 'title' => ['Some long title...'], + ], + 'http://ns.adobe.com/photoshop/1.0/' => [ + 'Credit' => '©', + ], + ], + ]), + XmpFormat::DEFAULT_PRESERVE_KEYS + ) + ); + } }