Skip to content

Commit

Permalink
fix: bad MMSI handling (#254)
Browse files Browse the repository at this point in the history
n2k-signalk is not expecting values to be zero length
https://github.com/SignalK/signalk-server/blob/f800fc9c62b249dc9c7f67252339408b0d8fa304/packages/streams/n2k-signalk.js#L121-L122
so if the MMSI seems to be not ok return undefined, as
any of the data in the delta don't make any sense with
a questionable MMSI.
  • Loading branch information
tkurki authored Dec 4, 2022
1 parent 4ecdaa5 commit 82d7a1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions n2kMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ var toDelta = function (n2k, state, customPgns = {}) {
//filter out invalid mmsi
let last = result.context.lastIndexOf(':')
if ( last != -1 && result.context.slice(last+1).length < 9 ) {
console.log('BAD: ' + result.context)
result.updates = []
console.error('bad MMSI: ' + result.context)
return
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/129038_ais_class_a.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('129038 Class A Update', function () {
"description": "AIS Class A Position Report",
"timestamp": "2022-05-09T13:38:38.917Z"
}
mapper.toDelta(msg, {}).updates.length.should.equal(0)
const deltaType = typeof mapper.toDelta(msg, {})
deltaType.should.equal('undefined')
})
})

Expand Down

0 comments on commit 82d7a1d

Please sign in to comment.