Skip to content

Commit

Permalink
Merge e4331b7 into 9861e24
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Jul 26, 2019
2 parents 9861e24 + e4331b7 commit ea67656
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions sentence.go
Expand Up @@ -56,6 +56,7 @@ func (s BaseSentence) String() string { return s.Raw }

// parseSentence parses a raw message into it's fields
func parseSentence(raw string) (BaseSentence, error) {
raw = strings.TrimSpace(raw)
startIndex := strings.IndexAny(raw, SentenceStart+SentenceStartEncapsulated)
if startIndex != 0 {
return BaseSentence{}, fmt.Errorf("nmea: sentence does not start with a '$' or '!'")
Expand Down
14 changes: 14 additions & 0 deletions sentence_test.go
Expand Up @@ -29,6 +29,20 @@ var sentencetests = []struct {
Raw: "$GPFOO,1,2,3.3,x,y,zz,*51",
},
},
{
name: "trim leading and trailing spaces",
raw: " $GPFOO,1,2,3.3,x,y,zz,*51 ",
datatype: "FOO",
talkerid: "GP",
prefix: "GPFOO",
sent: BaseSentence{
Talker: "GP",
Type: "FOO",
Fields: []string{"1", "2", "3.3", "x", "y", "zz", ""},
Checksum: "51",
Raw: "$GPFOO,1,2,3.3,x,y,zz,*51",
},
},
{
name: "good parsing",
raw: "$GPRMC,235236,A,3925.9479,N,11945.9211,W,44.7,153.6,250905,15.2,E,A*0C",
Expand Down

0 comments on commit ea67656

Please sign in to comment.