-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(site): quote colon-containing values in filter serialization #28254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { parseFilterQuery, stringifyFilter } from "./filterQuery"; | ||
|
|
||
| describe("stringifyFilter", () => { | ||
| it("leaves simple values unquoted", () => { | ||
| expect(stringifyFilter({ initiator: "me" })).toBe("initiator:me"); | ||
| }); | ||
|
|
||
| it("quotes values containing spaces", () => { | ||
| expect(stringifyFilter({ session_id: "abc def" })).toBe( | ||
| 'session_id:"abc def"', | ||
| ); | ||
| }); | ||
|
|
||
| it("quotes values containing colons so the backend parser accepts them", () => { | ||
| expect(stringifyFilter({ started_after: "2026-08-16T20:42:00Z" })).toBe( | ||
| 'started_after:"2026-08-16T20:42:00Z"', | ||
| ); | ||
| }); | ||
|
|
||
| it("drops empty values", () => { | ||
| expect(stringifyFilter({ initiator: undefined, model: "gpt-4" })).toBe( | ||
| "model:gpt-4", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("parseFilterQuery", () => { | ||
| it("round-trips quoted timestamp values", () => { | ||
| const values = { | ||
| initiator: "me", | ||
| started_after: "2026-08-16T20:42:00Z", | ||
| started_before: "2026-08-17T20:42:00Z", | ||
| }; | ||
| expect(parseFilterQuery(stringifyFilter(values))).toEqual(values); | ||
| }); | ||
|
|
||
| it("parses unquoted and quoted pairs", () => { | ||
| expect(parseFilterQuery('initiator:me session_id:"abc def"')).toEqual({ | ||
| initiator: "me", | ||
| session_id: "abc def", | ||
| }); | ||
| }); | ||
|
|
||
| it("returns an empty object for an empty query", () => { | ||
| expect(parseFilterQuery("")).toEqual({}); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| export type FilterValues = Record<string, string | undefined>; | ||
|
|
||
| export 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; | ||
| }; | ||
|
|
||
| // 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(":"); | ||
|
Comment on lines
+22
to
+25
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self-review: This is the meat of the change. |
||
|
|
||
| export const stringifyFilter = (filterValue: FilterValues): string => { | ||
| let result = ""; | ||
|
|
||
| for (const key in filterValue) { | ||
| const value = filterValue[key]; | ||
| if (value) { | ||
| result += needsQuotes(value) ? `${key}:"${value}" ` : `${key}:${value} `; | ||
| } | ||
| } | ||
|
|
||
| return result.trim(); | ||
| }; | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self-review: moved to
filterQuery.tsso it can be tested properly