Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Course API - check nextPoint value more rigorously #1840

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
16 changes: 14 additions & 2 deletions src/api/course/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,26 @@ export class CourseApi {
})
}

/** Test for valid Signal K position */
private isValidPosition(position: Position): boolean {
return (
typeof position?.latitude === 'number' &&
typeof position?.latitude === 'number' &&
position?.latitude >= -90 &&
position?.latitude <= 90 &&
position?.longitude >= -180 &&
position?.longitude <= 180
)
}

/** Process stream value and take action
* @param cmdSource Object describing the source of the update
* @param pos Destination location value in the update
*/
private async parseStreamValue(cmdSource: CommandSource, pos: Position) {
if (!this.cmdSource) {
// New source
if (!pos) {
if (!this.isValidPosition(pos)) {
return
}
debug('parseStreamValue:', 'Setting Destination...')
Expand Down Expand Up @@ -805,7 +817,7 @@ export class CourseApi {
throw new Error(`Invalid href! (${dest.href})`)
}
} else if ('position' in dest) {
if (isValidCoordinate(dest.position)) {
if (this.isValidPosition(dest.position)) {
newCourse.nextPoint = {
position: dest.position,
type: Location
Expand Down