diff --git a/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt b/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt index 2ea5ab2..8cf9714 100644 --- a/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt +++ b/src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt @@ -12,11 +12,23 @@ object DomParser { fun parseDocumentFromString(input: String): Document { + /* + * We encountered a situation where the XMP had NUL characters at the end + * for unknown reasons. This caused an exception in the parser. + * The test images IMG_0001.jpg and IMG_0002.jpg on the iOS simulator + * exhibited this issue, indicating that it could occur in real-world + * scenarios as well. To address this, we now trim all whitespaces and + * ISO control characters from the XMP to ensure its proper parsing. + */ + val trimmedInput = input.trim { + it.isWhitespace() || it.isISOControl() + } + try { val writer = DomWriter() - val reader = XmlStreaming.newReader(input) + val reader = XmlStreaming.newReader(trimmedInput) do { val event = reader.next() diff --git a/src/commonTest/resources/com/ashampoo/xmp/sample_2.xmp b/src/commonTest/resources/com/ashampoo/xmp/sample_2.xmp index 0fbf2e5..0031005 100644 Binary files a/src/commonTest/resources/com/ashampoo/xmp/sample_2.xmp and b/src/commonTest/resources/com/ashampoo/xmp/sample_2.xmp differ diff --git a/src/commonTest/resources/com/ashampoo/xmp/sample_3.xmp b/src/commonTest/resources/com/ashampoo/xmp/sample_3.xmp index 3275dc1..90aff58 100644 Binary files a/src/commonTest/resources/com/ashampoo/xmp/sample_3.xmp and b/src/commonTest/resources/com/ashampoo/xmp/sample_3.xmp differ diff --git a/src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp b/src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp index 649c5c9..b19cd57 100644 --- a/src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp +++ b/src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp @@ -296,28 +296,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + +