fix(grid): accept 8-char extended locators in the logging form & stations API#249
Merged
Merged
Conversation
… API Commit #246 added canonical 8-character (extended) Maidenhead support to `src/lib/grid.ts` (`isValidGrid`, `gridToLatLon`), and #248 uses the on-air station's grid as the distance/bearing origin. But three input validators kept their own 4/6-only regex and drifted behind: - `new-contact` form's inline `validateGridLocator` - `POST /api/stations` - `PUT /api/stations/[id]` Result: typing an 8-char grid (e.g. `FN31pr55`) into the logging form showed "Invalid grid locator format" and blocked save, and saving an 8-char station grid — the exact locator used as the distance origin — 400'd. VHF/UHF/ microwave and satellite operators log 8-char locators for the extra precision, so this silently rejected valid input. Centralize the check as `gridLocatorError(grid)` in the canonical grid module (null for blank/valid, message otherwise) and route all three call sites through it, so the form and the API can never drift from `isValidGrid` again. Tested: added unit coverage for `gridLocatorError` (blank, 4/6/8-char, malformed); `grid.spec.ts` 30/30 pass; typecheck, lint, and build all clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Commit #246 taught the app to understand 8-character (extended) Maidenhead locators —
isValidGridandgridToLatLoninsrc/lib/grid.tsaccept and geolocate them — and #248 uses the on-air station's grid as the origin for the live distance/bearing readout. VHF/UHF/microwave and satellite operators log 8-char locators for the extra precision.But three input validators never got the memo and kept their own 4/6-character-only regex (
/^[A-R]{2}[0-9]{2}([A-X]{2})?$/):new-contactlogging form's inlinevalidateGridLocatorPOST /api/stationsPUT /api/stations/[id]So the app that computes a distance from an 8-char grid wouldn't let you enter one:
FN31pr55into the logging form's grid field showed "Invalid grid locator format" and blocked the save.This is the same "local list/regex drifts behind the canonical
src/libmodule" class of bug fixed for band and mode filters in #241/#242.Solution
Add one canonical helper to the grid module and route all three call sites through it:
Because it delegates to
isValidGrid, the logging form and the stations API can no longer drift from the rest of the app. No schema or response-shape changes; validation is only loosened to accept locators the app already stores and geolocates, so it's fully backwards compatible.Testing
gridLocatorError(blank/whitespace → no error; 4/6/8-char → valid; malformed → message) intests/grid.spec.ts.npx playwright test grid.spec.ts— 30/30 pass.npm run typecheck,npm run lint,npm run build— all clean.Future follow-up
POST /api/stationsandPUT /api/stations/[id]share a fair amount of validation logic (callsign, grid, power, zones) that could be extracted into one shared validator; out of scope here./stations/new,/stations/[id]/edit) rely on server-side validation for the grid; adding matching inline feedback viagridLocatorErrorwould be a nice parity touch.🤖 Generated with Claude Code