Skip to content

fix: prevent API calls for whitespace-only search input#352

Merged
nilsnolde merged 2 commits intovalhalla:masterfrom
thisisharsh7:fix/whitespace-search-validation
Mar 6, 2026
Merged

fix: prevent API calls for whitespace-only search input#352
nilsnolde merged 2 commits intovalhalla:masterfrom
thisisharsh7:fix/whitespace-search-validation

Conversation

@thisisharsh7
Copy link
Contributor

Fixes Issue

Closes #347

What's the problem?

You can type just spaces into the waypoint search field and it'll actually make an API call. The API returns a 400 error saying "Nothing to search for", which is correct, but we shouldn't be making that call in the first place.

Why does this happen?

The code checks if the input length is greater than 0 before searching:

if (internalValue.length === 0) return;

But " ".length is 3, not 0, so it passes the check and triggers the API call.

The fix

Added .trim() before checking the length in a few places:

  1. Before making the API call
  2. Before checking if we should search on Enter key
  3. When sending the value to the geocoding API

Created a trimmedValue variable to avoid calling .trim() multiple times:

const trimmedValue = internalValue.trim();

Testing

  • Type only spaces → No API call
  • Type actual location → Works normally
  • Type location with leading/trailing spaces → Gets trimmed, works

Note: This PR was created with AI assistance. I discovered the bug through manual testing, and AI helped with debugging. I've reviewed, understood, and verified the fix works as expected.

@ghost
Copy link

ghost commented Mar 6, 2026

Preview is ready! 🚀 You can view it here: https://valhalla-app-tests.gis-ops.com/352

@nilsnolde nilsnolde enabled auto-merge (squash) March 6, 2026 10:54
@nilsnolde nilsnolde merged commit a6a6975 into valhalla:master Mar 6, 2026
3 checks passed
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.

Search field accepts whitespace-only input causing unnecessary API calls

3 participants