diff options
| author | rsudev <rasch@munin-soft.de> | 2013-04-07 13:01:37 +0200 |
|---|---|---|
| committer | rsudev <rasch@munin-soft.de> | 2013-04-07 13:02:24 +0200 |
| commit | 37c90405dff48b5996fc8103e071fcd9c54f7a21 (patch) | |
| tree | 5e8a44f5f72409c9db0dde97f39f20f4b63787ba | |
| parent | b00397af070060318a5163464051b91908cf223d (diff) | |
| download | cgeo-37c90405dff48b5996fc8103e071fcd9c54f7a21.zip cgeo-37c90405dff48b5996fc8103e071fcd9c54f7a21.tar.gz cgeo-37c90405dff48b5996fc8103e071fcd9c54f7a21.tar.bz2 | |
Fixes #2635, crash during gpx export
Added utf-16 codepoint surrogate handling to xml serializer
| -rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/org/kxml2/io/KXmlSerializer.java | 16 |
2 files changed, 15 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index 8303137..c2a58b7 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -14,6 +14,7 @@ import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.XmlUtils; +import cgeo.org.kxml2.io.KXmlSerializer; import org.apache.commons.lang3.StringUtils; import org.xmlpull.v1.XmlSerializer; @@ -27,7 +28,6 @@ import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Environment; -import android.util.Xml; import android.view.ContextThemeWrapper; import android.view.View; import android.widget.CheckBox; @@ -138,7 +138,7 @@ class GpxExport extends AbstractExport { final File exportLocation = new File(Settings.getGpxExportDir()); exportLocation.mkdirs(); - final XmlSerializer gpx = Xml.newSerializer(); + final XmlSerializer gpx = new KXmlSerializer(); writer = new FileWriter(exportFile); gpx.setOutput(writer); diff --git a/main/src/cgeo/org/kxml2/io/KXmlSerializer.java b/main/src/cgeo/org/kxml2/io/KXmlSerializer.java index a9dde8c..027ff53 100644 --- a/main/src/cgeo/org/kxml2/io/KXmlSerializer.java +++ b/main/src/cgeo/org/kxml2/io/KXmlSerializer.java @@ -130,11 +130,21 @@ public class KXmlSerializer implements XmlSerializer { } // BEGIN android-changed: refuse to output invalid characters // See http://www.w3.org/TR/REC-xml/#charsets for definition. - // No other Java XML writer we know of does this, but no Java - // XML reader we know of is able to parse the bad output we'd - // otherwise generate. + // Corrected for c:geo to handle utf-16 codepoint surrogates correctly + // See http://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B10000_to_U.2B10FFFF // Note: tab, newline, and carriage return have already been // handled above. + // Check for lead surrogate + if (c >= 0xd800 && c <= 0xdbff) { + + if (i + 1 < s.length()) { + writer.write(s.substring(i, i + 1)); + i++; + break; + } + // if the lead surrogate is at the string end, it's not valid utf-16 + reportInvalidCharacter(c); + } boolean valid = (c >= 0x20 && c <= 0xd7ff) || (c >= 0xe000 && c <= 0xfffd); if (!valid) { reportInvalidCharacter(c); |
