Skip to content

Commit

Permalink
Edit parser to return None for empty ele tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ebcrowder committed May 27, 2022
1 parent 9cd5e4b commit 9fc5080
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/parser/waypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ pub fn consume<R: Read>(context: &mut Context<R>, tagname: &'static str) -> GpxR
match name.local_name.as_ref() {
"ele" => {
// Cast the elevation to an f64, from a string.
// empty elevation tags will be parsed as 0.00
waypoint.elevation = Some(
string::consume(context, "ele", true)?
.parse()
.unwrap_or_default(),
)
waypoint.elevation = match string::consume(context, "ele", false) {
Ok(v) => Some(v.parse()?),
Err(_) => None,
}
}
"speed" if context.version == GpxVersion::Gpx10 => {
// Speed is from GPX 1.0
Expand Down
5 changes: 2 additions & 3 deletions tests/gpx_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ fn gpx_reader_read_test_empty_elevation() {
for track in &res.tracks {
for segment in &track.segments {
for point in &segment.points {
// Elevation should default to 0.00
let elevation = point.elevation.unwrap();
assert!(elevation == 0.00);
let elevation = point.elevation.is_none();
assert_eq!(elevation, true);
}
}
}
Expand Down

0 comments on commit 9fc5080

Please sign in to comment.