-
Notifications
You must be signed in to change notification settings - Fork 5
Description
How to test:
take a kml file with a place mark with a name that contains an unusual character:
Heiglhofstraße 1-3
What happens:
the final annotation has a title == "ße 1-3"
What is expected:
the final annotation has a title == "Heiglhofstraße 1-3"
Cause:
Any XML SAX parser is allowed to divide strings into chunks and present the chunks as separate callbacks to method parser(_ parser: XMLParser, foundCharacters string: String).
SAX Parsers are not only allowed to do this, most parsers actually do this and so is Apples implementation.
In our case, parser(_ parser: XMLParser, foundCharacters string: String) is called twice:
once with string "Heiglhofstra" and once with "ße 1-3"
The current implementation throws away the first string when assigning the annotation title.
partial fix for my test case (this is a dirty hack, see comment below):
case .some(.name):
if let oldKmlStr = kmlObjectLookup[.name] as? KMLStringValue {
let value = oldKmlStr.value + string
kmlObjectLookup[.name] = KMLStringValue(value: value)
} else {
kmlObjectLookup[.name] = KMLStringValue(value: string)
}
(be aware that I removed the where condition which is also a bug - probably your first attempt to fix the problem)
The same bug appears probably here
case .some(.description):
kmlObjectLookup[.description] = KMLStringValue(value: string)
But this is not relevant for my data.
Usually what I do when implementing a SAX parser, is collecting all the string fragments.
At endElement I look if there is some collected string data and call a method that looks like your parser(_ parser: XMLParser, foundCharacters string: String) implementation. This would be the good solution, not my quick hack above