Skip to content

Leave out invalid XML characters and write single line breaks in GPX/… - #1330

Merged
AgreeDK merged 1 commit into
OpenSAK-Org:betafrom
nagisml:fix/1329-gpx-invalid-chars-crlf
Nov 18, 2026
Merged

AgreeDK merged 1 commit into
OpenSAK-Org:betafrom
nagisml:fix/1329-gpx-invalid-chars-crlf

Conversation

@nagisml

@nagisml nagisml commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

…GGZ exports

The GPX/GGZ export wrote text exactly as stored in the database, which caused two problems:

  • Control characters that XML 1.0 doesn't allow (e.g. \x02 in Adventure Lab descriptions imported from GSAK) were written as they are. A single one makes the whole file invalid XML, and strict readers such as c:geo reject it.
  • Text with CR LF line breaks (from GSAK and geocaching.com) came out as CR CR LF in a text-mode file on Windows. Parsers read that as two line breaks, so every multi-line log, user note and description got empty lines between its lines.

_xml_chunk(), which serializes every element of the GPX, GGZ and LOC export, now removes the characters XML 1.0 doesn't allow (C0 controls except tab, LF and CR; U+FFFE, U+FFFF; lone surrogates) and writes line breaks in the text as LF. Parsers read CR LF and a lone CR as LF anyway, so the text is unchanged; a text-mode file on Windows now has a single CR LF per line break, as GSAK's own export does.

The line breaks are fixed in the writer instead of opening the file with newline="", because macros save through safe_write_stream(), which also opens the file in text mode and is used for every other file a macro writes. This way the export dialog, Send to GPS (including MTP) and macros are all fixed.

fixes #1329

…GGZ exports

The GPX/GGZ export wrote text exactly as stored in the database, which
caused two problems:

* Control characters that XML 1.0 doesn't allow (e.g. \x02 in Adventure
  Lab descriptions imported from GSAK) were written as they are. A single
  one makes the whole file invalid XML, and strict readers such as c:geo
  reject it.
* Text with CR LF line breaks (from GSAK and geocaching.com) came out as
  CR CR LF in a text-mode file on Windows. Parsers read that as two line
  breaks, so every multi-line log, user note and description got empty
  lines between its lines.

_xml_chunk(), which serializes every element of the GPX, GGZ and LOC
export, now removes the characters XML 1.0 doesn't allow (C0 controls
except tab, LF and CR; U+FFFE, U+FFFF; lone surrogates) and writes line
breaks in the text as LF. Parsers read CR LF and a lone CR as LF anyway,
so the text is unchanged; a text-mode file on Windows now has a single
CR LF per line break, as GSAK's own export does.

The line breaks are fixed in the writer instead of opening the file with
newline="", because macros save through safe_write_stream(), which also
opens the file in text mode and is used for every other file a macro
writes. This way the export dialog, Send to GPS (including MTP) and
macros are all fixed.

fixes OpenSAK-Org#1329
@AgreeDK
AgreeDK merged commit ca30531 into OpenSAK-Org:beta Nov 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants