Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- [#113](https://github.com/georust/gpx/pull/113): Add GpxError::UnsupportedVersionError
- [#110](https://github.com/georust/gpx/pull/110): Add Gpx::new() method, tidy up examples in the README
- [#101](https://github.com/georust/gpx/pull/101): Write speed to GPX 1.0 files

Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum GpxError {
XmlParseError(#[from] xml::reader::Error),
#[error("unknown GPX version: `{0}`")]
UnknownVersionError(crate::types::GpxVersion),
#[error("unsupported GPX version: `{0}`")]
UnsupportedVersionError(String),
#[error("tag opened twice: `{0}`")]
TagOpenedTwice(&'static str),
#[error("error while parsing 'track' segment")]
Expand Down
2 changes: 1 addition & 1 deletion src/parser/gpx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn version_string_to_version(version_str: &str) -> GpxResult<GpxVersion> {
match version_str {
"1.0" => Ok(GpxVersion::Gpx10),
"1.1" => Ok(GpxVersion::Gpx11),
_ => Err(GpxError::UnknownVersionError(GpxVersion::Unknown)),
_ => Err(GpxError::UnsupportedVersionError(version_str.to_owned())),
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/unsupported_version.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" creator="Garmin Edge 530" version="8.0">
<metadata>
<link href="https://gotoes.org/strava/Combine_GPX_TCX_FIT_Files.php">
<text>GOTOES STRAVA TOOLS</text>
</link>
<time>2020-07-23T21:29:05Z</time>
</metadata>
</gpx>
18 changes: 17 additions & 1 deletion tests/gpx_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use geo::algorithm::haversine_distance::HaversineDistance;
use geo::euclidean_length::EuclideanLength;
use geo_types::{Geometry, Point};

use gpx::{read, Fix};
use gpx::{errors::GpxError, read, Fix};
use std::error::Error;

use time::{Date, Month, PrimitiveDateTime, Time};
Expand All @@ -26,6 +26,22 @@ fn gpx_reader_read_test_badxml() {
assert!(result.is_err());
}

#[test]
fn gpx_reader_read_unsupported_gpx_version() {
let file = File::open("tests/fixtures/unsupported_version.gpx").unwrap();
let reader = BufReader::new(file);

let result = read(reader);

// Make sure the error includes the actual version
match result {
Err(GpxError::UnsupportedVersionError(version)) => {
assert_eq!(version, "8.0");
}
_ => panic!("expected UnsupportedVersionError, got: {:?}", result),
}
}

#[test]
fn gpx_reader_read_test_wikipedia() {
// Should not give an error, and should have all the correct data.
Expand Down