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 @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
### Changed
- Fixed panic on messages with multi-byte characters in the checksum

## [0.11.0] - 2024-06-13
### Added
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ impl NmeaParser {
}
};

if !sentence.is_ascii() {
return Err(ParseError::InvalidSentence(String::from(
"Invalid characters in sentence",
)));
}

// Calculate NMEA checksum and compare it to the given one. Also, remove the checksum part
// from the sentence to simplify next processing steps.
let mut checksum = 0;
Expand Down Expand Up @@ -625,9 +631,9 @@ mod test {
fn test_parse_invalid_sentence() {
let mut p = NmeaParser::new();
assert_eq!(
p.parse_sentence("$޴GAGSV,,"),
p.parse_sentence("$GAGSV^,,"),
Err(ParseError::InvalidSentence(
"Invalid characters in sentence type: $\u{7b4}GAGSV".to_string()
"Invalid characters in sentence type: $GAGSV^".to_string()
))
);
assert_eq!(
Expand All @@ -648,6 +654,12 @@ mod test {
"Invalid NMEA sentence: !".to_string()
))
);
assert_eq!(
p.parse_sentence("$GAGSV,,*💖"),
Err(ParseError::InvalidSentence(
"Invalid characters in sentence".to_string()
))
);
}
#[test]
fn test_parse_prefix_chars() {
Expand Down