Skip to content

RTFDB-4842: Improve user input handling in "mapbox-gl-geocoder" - #558

Open
pahuta wants to merge 2 commits into
RTFDB-4842-improve-user-input-handling-2from
RTFDB-4842-improve-user-input-handling-3
Open

RTFDB-4842: Improve user input handling in "mapbox-gl-geocoder"#558
pahuta wants to merge 2 commits into
RTFDB-4842-improve-user-input-handling-2from
RTFDB-4842-improve-user-input-handling-3

Conversation

@pahuta

@pahuta pahuta commented Aug 2, 2026

Copy link
Copy Markdown
  • Remove numeric-range bound on coordinate detection regex so it matches how the Geocoding v5 API itself detects coordinate-shaped queries, fixing forward/reverse misclassification (422 errors) for out-of-range coordinate-like input
  • Require a comma (with optional surrounding whitespace) as the coordinate separator so whitespace-only separated numbers are still treated as a forward query
  • Deduplicate the coordinate regex in the forward-request branch, reusing the shared utils.REVERSE_GEOCODE_COORD_RGX
  • Add corresponding test cases and changelog entry

Since code-scanning found an issue https://github.com/mapbox/mapbox-gl-geocoder/security/code-scanning/7, I also:

  • Reject search input over 256 characters (mirrors the Geocoding v5 API's own limit) with a dedicated "search is too long" error instead of sending it to the API.
  • Centralize attribution-hiding in _renderMessage() so it's consistently hidden for every error/no-results message.
  • Fix two independent races with the suggestions library's own native keyup/paste listeners on the input element that could redraw the list from stale/empty data and wipe out a just-rendered message — most visibly, pasting an over-limit value directly (via keyboard shortcut) silently failed to show the "too long" error.

https://mapbox.atlassian.net/browse/RTFDB-4842

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • run npm run docs and commit changes to API.md
  • update CHANGELOG.md with changes under main heading before merging

Previous behavior vs new behavior:

reverse.mp4

Add checking search input length before sending requests to Geocoding v5 API.

Previous behavior

old.mp4

New behavior

new.mp4

pahuta added 2 commits August 2, 2026 14:07
- Remove numeric-range bound on coordinate detection regex so it matches how the Geocoding v5 API itself detects coordinate-shaped queries, fixing forward/reverse misclassification (422 errors) for out-of-range coordinate-like input
- Require a comma (with optional surrounding whitespace) as the coordinate separator so whitespace-only separated numbers are still treated as a forward query
- Deduplicate the coordinate regex in the forward-request branch, reusing the shared utils.REVERSE_GEOCODE_COORD_RGX
- Add corresponding test cases and changelog entry

https://mapbox.atlassian.net/browse/RTFDB-4842
@pahuta
pahuta marked this pull request as ready for review August 5, 2026 09:42
@pahuta
pahuta requested a review from a team as a code owner August 5, 2026 09:42
@pahuta
pahuta requested review from underoot and removed request for a team August 5, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant