Skip to content

fix: trim whitespace in search filters to prevent API 400 errors#6934

Open
talissoncosta wants to merge 2 commits intorefactor/feature-fetchingfrom
fix/trim-value-search-whitespace
Open

fix: trim whitespace in search filters to prevent API 400 errors#6934
talissoncosta wants to merge 2 commits intorefactor/feature-fetchingfrom
fix/trim-value-search-whitespace

Conversation

@talissoncosta
Copy link
Contributor

@talissoncosta talissoncosta commented Mar 12, 2026

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to #6930

Typing only whitespace (e.g. a space) in the feature search or value search fields sent search=%20 to the API, which returned a 400 "This field may not be blank." error.

  • featureFilterParams.ts: Add normaliseFilters — a centralised function that trims search and value_search fields, converting whitespace-only values to null
  • useFeatureFilters.ts: Use normaliseFilters in handleFilterChange with isEqual (lodash) to skip state updates when the effective filter hasn't changed — preventing unnecessary API requests
  • featureFilterParams.test.ts: Add unit tests for normaliseFilters covering trim, null, and empty string edge cases

How did you test this code?

  1. Navigate to the features page
  2. Click the search input and type only spaces
  3. Verify no API requests are made and no 400 errors occur
  4. Type a valid search term with leading/trailing spaces — verify the trimmed value is sent
  5. Open the Value filter, type only spaces — verify no request is made
  6. Unit tests: npm run test:unit -- --testPathPatterns=featureFilterParams (32 tests pass)

@talissoncosta talissoncosta requested a review from a team as a code owner March 12, 2026 15:17
@talissoncosta talissoncosta requested review from kyle-ssg and removed request for a team March 12, 2026 15:17
@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview, Comment Mar 12, 2026 3:40pm
flagsmith-frontend-staging Ready Ready Preview, Comment Mar 12, 2026 3:40pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 12, 2026 3:40pm

Request Review

@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6934 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6934 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6934 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6934 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6934 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6934 Finished ✅ Results

Typing only spaces in the value search filter sent whitespace to the
API, which returned a 400 "This field may not be blank." error. Trim
the value before sending in both the RTK Query and Flux store paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  46.4 seconds
commit  b7f106c
info  🔄 Run: #15263 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  52.1 seconds
commit  b7f106c
info  🔄 Run: #15263 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  46.5 seconds
commit  4e34ff7
info  🔄 Run: #15264 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  29.5 seconds
commit  4e34ff7
info  🔄 Run: #15264 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  59.5 seconds
commit  b7f106c
info  🔄 Run: #15263 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  56.6 seconds
commit  b7f106c
info  🔄 Run: #15263 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  58.2 seconds
commit  4e34ff7
info  🔄 Run: #15264 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  4e34ff7
info  🔄 Run: #15264 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  51.2 seconds
commit  bf43459
info  🔄 Run: #15265 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  51.6 seconds
commit  bf43459
info  🔄 Run: #15265 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  54.7 seconds
commit  bf43459
info  🔄 Run: #15265 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  60 seconds
commit  bf43459
info  🔄 Run: #15265 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  11.4 seconds
commit  c81cea0
info  🔄 Run: #15266 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  46.4 seconds
commit  c81cea0
info  🔄 Run: #15266 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  35.5 seconds
commit  c81cea0
info  🔄 Run: #15266 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  29.2 seconds
commit  c81cea0
info  🔄 Run: #15266 (attempt 1)

Extract a single normaliseFilters function to trim search and
value_search fields, preventing whitespace-only API requests.
Add unit tests covering trim, null, and empty string edge cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant