Skip to content

Commit

Permalink
Fix unterminated entity reference error (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi authored Oct 21, 2023
1 parent 858d8be commit d724e94
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions src/Metadata/XmpFormat.php
Original file line number Diff line number Diff line change
@@ -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))
;
}
}
}
38 changes: 38 additions & 0 deletions tests/Metadata/XmpFormatTest.php
Original file line number Diff line number Diff line change
@@ -202,4 +202,42 @@ public function getSerialize(): \Generator
'',
];
}

public function testSerializeValuesWithAmpersands(): void
{
$this->assertSame(
"<?xpacket begin=\"\u{FEFF}\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
.'<x:xmpmeta xmlns:x="adobe:ns:meta/">'
.'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'
.'<rdf:Description '
.'xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" '
.'photoshop:Credit="&amp;copy"'
.'>'
.'<dc:rights xmlns:dc="http://purl.org/dc/elements/1.1/">'
.'<rdf:Bag><rdf:li>Rights</rdf:li><rdf:li>&amp; more</rdf:li></rdf:Bag>'
.'</dc:rights>'
.'<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">'
.'<rdf:Bag><rdf:li>Creator 1</rdf:li><rdf:li>&amp;crea</rdf:li></rdf:Bag>'
.'</dc:creator>'
.'</rdf:Description>'
.'</rdf:RDF>'
.'</x:xmpmeta>'
.'<?xpacket end="w"?>',
(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' => '&copy',
],
],
]),
XmpFormat::DEFAULT_PRESERVE_KEYS
)
);
}
}

0 comments on commit d724e94

Please sign in to comment.