Repository navigation
Read GPX files as UTF-8 on every platform - #933
Merged
Merged
Conversation
A GPX file was decoded in the encoding of the locale, as v0.14.7 did
with open("r"): cp1252 on Western Windows, cp936 on Chinese Windows.
GPX files are almost always UTF-8. There, a UTF-8 GPX with "Á", "Í",
"Ð", "Ý" or most CJK characters in its names failed with
UnicodeDecodeError, as their bytes are undefined in cp1252, and the
user was told that it is not a valid GPX file; other accented letters
only came out garbled. On Linux and macOS, a GPX in another encoding,
such as ISO-8859-1 with "Café" in a name, failed the same way.
Decode it as UTF-8 with errors="replace", as NMEA logs are, so that a
byte that is not UTF-8 only turns a letter of a name into U+FFFD:
positions and times are ASCII. gpxpy still reads the file opened in
text mode itself, and a byte order mark is still ignored. A UTF-16 GPX
still fails as not a valid GPX file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A GPX file was decoded in the encoding of the locale, as v0.14.7 did with
open("r"): cp1252 on Western Windows, cp936 on Chinese Windows. GPX files are almost always UTF-8. There, a UTF-8 GPX with "Á", "Í", "Ð", "Ý" or most CJK characters in its names failed withUnicodeDecodeError, as their bytes are undefined in cp1252, and the user was told "X.gpx is not a valid GPX file. Replace it with a valid GPX file."; other accented letters only came out garbled. On Linux and macOS, a GPX in another encoding, such as ISO-8859-1 with "Café" in a name, failed the same way.Decode it as UTF-8 with
errors="replace", as NMEA logs are (#902), so that a byte that is not UTF-8 only turns a letter of a name into U+FFFD: positions and times are ASCII. gpxpy still reads the file opened in text mode itself (#912's memory fix), and a byte order mark is still ignored. A UTF-16 GPX still fails asMapillaryInvalidGPXError.process VIDEO --video_geotag_source gpx --geotag_source_path X.gpx --interpolation_use_gpx_start_time: ready, with the same 60 points as its UTF-8 copy. Main:MapillaryInvalidGPXError, exit 6.Compared with main on
process,video_processandprocess_and_upload --dry_run, on images and videos of many cameras with the default and other sources, the outputs and exit codes are the same.Unit and integration tests, doctests,
mypy --python-version 3.9,ruff check,ruff format --checkandusort diffare clean.