fix(site): quote colon-containing values in filter serialization - #28254
Conversation
stringifyFilter only quoted values containing spaces, so filter values like RFC 3339 timestamps (2026-08-16T20:42:00Z) were emitted unquoted and the backend query parser rejected their colons. Quote values containing colons too; they were never valid unquoted. Extract parseFilterQuery/stringifyFilter into filterQuery.ts with unit tests.
| // Values containing spaces or colons must be quoted: the backend query | ||
| // parser splits unquoted elements on ':' and rejects more than one colon. | ||
| const needsQuotes = (value: string): boolean => | ||
| value.includes(" ") || value.includes(":"); |
There was a problem hiding this comment.
self-review: This is the meat of the change.
| const parseFilterQuery = (filterQuery: string): FilterValues => { | ||
| if (filterQuery === "") { | ||
| return {}; | ||
| } | ||
|
|
||
| const result: FilterValues = {}; | ||
| const keyValuePair = /(\w+):"([^"]+)"|(\w+):(\S+)/g; | ||
|
|
||
| for (const match of filterQuery.matchAll(keyValuePair)) { | ||
| const key = match[1] ?? match[3]; | ||
| const value = match[2] ?? match[4]; | ||
| if (key && value) { | ||
| result[key] = value; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const stringifyFilter = (filterValue: FilterValues): string => { | ||
| let result = ""; | ||
|
|
||
| for (const key in filterValue) { | ||
| const value = filterValue[key]; | ||
| if (value) { | ||
| const needsQuotes = value.includes(" "); | ||
| result += needsQuotes ? `${key}:"${value}" ` : `${key}:${value} `; | ||
| } | ||
| } | ||
|
|
||
| return result.trim(); | ||
| }; | ||
|
|
There was a problem hiding this comment.
self-review: moved to filterQuery.ts so it can be tested properly
There was a problem hiding this comment.
Pull request overview
This PR fixes filter query re-serialization in the shared Filter component so values that contain colons (notably RFC 3339 timestamps) remain valid for the backend search parser when the query is regenerated, and it extracts the parsing/serialization helpers into a dedicated module with unit tests.
Changes:
- Updated filter serialization to quote values containing
:in addition to spaces. - Extracted
parseFilterQueryandstringifyFilterintofilterQuery.tsfor reuse and isolation. - Added Vitest unit tests, including a quoted timestamp round-trip.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| site/src/components/Filter/filterQuery.ts | New shared helpers for parsing and serializing filter query strings, including colon-aware quoting. |
| site/src/components/Filter/filterQuery.test.ts | Unit tests validating quoting behavior and parse/stringify round-trips (including RFC 3339 timestamps). |
| site/src/components/Filter/Filter.tsx | Switched the Filter component to use the extracted filterQuery helpers instead of inline implementations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
stringifyFilterin the sharedFiltercomponent only quoted values containing spaces. Filter values like RFC 3339 timestamps (2026-08-16T20:42:00Z) contain colons but no spaces, so when any filter was edited and the whole query re-serialized, the timestamp went out unquoted and the backendsearchTermsparser rejected it (Query element ... can only contain 1 ':').Quote values containing colons as well; they were never valid unquoted because the backend parser already rejects them. Extract
parseFilterQuery/stringifyFilterintofilterQuery.tswith unit tests, including a round-trip of quoted timestamps.Part of AIGOV-580
Generated by Coder Agents on behalf of @johnstcn.$
Stack: #28254 (filterQuery fix) \u2192 #28255 (component) \u2192 #28256 (sessions page)