MarksMapStateService.moveWaypoint inserts undefined for an out-of-range fromIndex #1062

Closed
opened 2026-08-13 06:02:11 +00:00 by spikerj · 1 comment
Owner

Wave 7 tick 5 a3 coverage of MarksMapStateService.moveWaypoint.

Where: projects/spikersoft/src/app/_services/marks-site/marks-map/marks-map-state.service.ts

What: moveWaypoint(fromIndex, toIndex) does:

const [movedItem] = newWaypoints.splice(fromIndex, 1);
newWaypoints.splice(toIndex, 0, movedItem);

If fromIndex is past the end of the list, splice returns [], so movedItem is undefined, and that hole is inserted at toIndex. A UI that reorders waypoints from a stale index can grow a phantom undefined stop and then crash when building a Directions request (waypoint.location.lat).

removeWaypoint already no-ops for an out-of-range index (filter keeps the list). moveWaypoint should do the same — return unchanged when fromIndex is not in range, rather than inserting undefined.

Would have caught: setWaypoints(['a','b']); moveWaypoint(9, 0) producing [undefined, 'a', 'b'].

Wave 7 tick 5 a3 coverage of `MarksMapStateService.moveWaypoint`. **Where:** `projects/spikersoft/src/app/_services/marks-site/marks-map/marks-map-state.service.ts` **What:** `moveWaypoint(fromIndex, toIndex)` does: ``` const [movedItem] = newWaypoints.splice(fromIndex, 1); newWaypoints.splice(toIndex, 0, movedItem); ``` If `fromIndex` is past the end of the list, `splice` returns `[]`, so `movedItem` is `undefined`, and that hole is inserted at `toIndex`. A UI that reorders waypoints from a stale index can grow a phantom `undefined` stop and then crash when building a Directions request (`waypoint.location.lat`). `removeWaypoint` already no-ops for an out-of-range index (filter keeps the list). `moveWaypoint` should do the same — return unchanged when `fromIndex` is not in range, rather than inserting `undefined`. **Would have caught:** `setWaypoints(['a','b']); moveWaypoint(9, 0)` producing `[undefined, 'a', 'b']`.
Author
Owner

Resolved in spikersoft-angular PR #819 (merged to master). moveWaypoint no longer inserts undefined for an out-of-range fromIndex. Closing.

Resolved in spikersoft-angular [PR #819](https://git.spikersoft.com/spikerj/spikersoft-angular/pulls/819) (merged to `master`). moveWaypoint no longer inserts undefined for an out-of-range fromIndex. Closing.
Sign in to join this conversation.