Skip to content

Commit

Permalink
Fix unterminated entity reference error
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Oct 21, 2023
1 parent 858d8be commit ce0b9b6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Metadata/XmpFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
;
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions tests/Metadata/XmpFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ce0b9b6

Please sign in to comment.