Skip to content

Commit

Permalink
FIX: Trim ISO characters in the input (#4)
Browse files Browse the repository at this point in the history
Fix: Robustness for ISO control characters at beginning or end of the XMP. Added some to the test data.
  • Loading branch information
StefanOltmann authored Jul 10, 2023
1 parent 083763c commit 937285f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
14 changes: 13 additions & 1 deletion src/commonMain/kotlin/com/ashampoo/xmp/impl/DomParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file modified src/commonTest/resources/com/ashampoo/xmp/sample_2.xmp
Binary file not shown.
Binary file modified src/commonTest/resources/com/ashampoo/xmp/sample_3.xmp
Binary file not shown.
51 changes: 26 additions & 25 deletions src/commonTest/resources/com/ashampoo/xmp/sample_4.xmp
Original file line number Diff line number Diff line change
Expand Up @@ -296,28 +296,29 @@
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
























<?xpacket end='w'?>
























<?xpacket end='w'?>

0 comments on commit 937285f

Please sign in to comment.