Skip to content

Commit 937285f

Browse files
FIX: Trim ISO characters in the input (#4)
Fix: Robustness for ISO control characters at beginning or end of the XMP. Added some to the test data.
1 parent 083763c commit 937285f

4 files changed

Lines changed: 39 additions & 26 deletions

File tree

src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,23 @@ object DomParser {
1212

1313
fun parseDocumentFromString(input: String): Document {
1414

15+
/*
16+
* We encountered a situation where the XMP had NUL characters at the end
17+
* for unknown reasons. This caused an exception in the parser.
18+
* The test images IMG_0001.jpg and IMG_0002.jpg on the iOS simulator
19+
* exhibited this issue, indicating that it could occur in real-world
20+
* scenarios as well. To address this, we now trim all whitespaces and
21+
* ISO control characters from the XMP to ensure its proper parsing.
22+
*/
23+
val trimmedInput = input.trim {
24+
it.isWhitespace() || it.isISOControl()
25+
}
26+
1527
try {
1628

1729
val writer = DomWriter()
1830

19-
val reader = XmlStreaming.newReader(input)
31+
val reader = XmlStreaming.newReader(trimmedInput)
2032

2133
do {
2234
val event = reader.next()
11 Bytes
Binary file not shown.
-2.33 KB
Binary file not shown.

src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,29 @@
296296
</rdf:Description>
297297
</rdf:RDF>
298298
</x:xmpmeta>
299-
300-
301-
302-
303-
304-
305-
306-
307-
308-
309-
310-
311-
312-
313-
314-
315-
316-
317-
318-
319-
320-
321-
322-
323-
<?xpacket end='w'?>
299+
300+
301+
302+
303+
304+
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+
317+
318+
319+
320+
321+
322+
323+
<?xpacket end='w'?>
324+

0 commit comments

Comments
 (0)