Skip to content

fix(frontend): quote each text value of a QueryKit filter, and refuse a value with a quote at an end - #372

Merged
pdevito3 merged 13 commits into
mainfrom
fix/querykit-filters
Oct 29, 2026
Merged

pdevito3 merged 13 commits into
mainfrom
fix/querykit-filters

Conversation

@pdevito3

@pdevito3 pdevito3 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Why

The filter builder put quotes around a text value only when the value had a space. A value with a quote, a hyphen, or a dot gave a 400 from QueryKit, and the text null found the rows with no value. Closes #363.

What changed

  • querykit-converter.ts puts each text value and each multiselect value in quotes. A value with a quote inside it goes in a QueryKit raw literal ("""a"b"""). The delimiter is longer than each run of quotes in the value. QueryKit has no escape in "...".
  • QueryKit 1.16.1 cannot hold two kinds of text value (see "The QueryKit limits" below). querykit-text.ts names them as TextValueFault:
    • endQuote: a value that starts or ends with a quote. The filter would match other text.
    • brackets: a whole value that starts with [ and ends with ], such as [DRAFT]. QueryKit refuses the filter with a 400.
  • The text control refuses such a value and tells the user why:
    • "A filter value cannot start or end with a quote. Remove the quote at the start or the end."
    • "A filter value cannot start with [ and end with ]. Remove the [ at the start or the ] at the end."
    • The field gets aria-invalid and aria-describedby, and the filter is not added.
    • A leading quote shows the message at once. Any other fault shows it when the user presses Enter or clicks Add Filter. The message does not show on a blur. On a blur, the message moved the buttons below the field under the pointer, so a click on Cancel or Case sensitive missed. Add Filter is enabled for any value that is not empty.
    • When the dialog edits a filter whose value has a fault, the message shows at once.
  • The multiselect control names each option with an end quote ("Clear the option X.") and marks it invalid. An option in brackets works, because QueryKit splits the list before it reads an item.
  • A FilterState from a preset or an initial state can hold a value with a fault. toQueryKitString does not throw for it. It leaves out that filter, and a group with no other filter. The badge of the filter gets a red outline, an alert icon, and the text "This filter is not used. Edit the filter, then change the value." The edit button of the badge has this text as its description. Before, toQueryKitString threw in render, and the demo page showed "Something went wrong!".
  • The operator between badges (AND, OR) and the grouping checkbox align with the badge, not with the badge and its message.
  • docs/frontend.md, the verify recipe, and its feature file show the quoted output and the limits.

The QueryKit limits

These are faults of QueryKit 1.16.1 and 1.16.2. A fix in QueryKit would let the filter builder drop each refusal.

A quote at an end. No literal form holds a quote at either end of a value. A probe tried "X", raw literals of 3 to 6 quotes, a padded raw literal, and a list item for the values "Paul", "Quoted, Quoted", and ". Each gave a ParsingException, the value without its end quote (""""Paul"""" finds Paul), or no rows. In QueryKit/FilterParser.cs:

  • RawStringLiteralParser takes the opening quotes with the greedy pattern "{3,}, so a quote after the delimiter becomes part of the delimiter.
  • right = right.Trim('"') removes the quotes at the ends of each string value, and the list parser does the same for each item.

A whole value in brackets. DoubleQuoteParser and RawStringLiteralParser return the content without its quotes, and RightSideValue.IsQuotedLiteral records that it was quoted. Then CreateRightExprFromType checks right.StartsWith("[") && right.EndsWith("]") and reads the value as a list, also when rightIsQuotedLiteral is true. So "[DRAFT]" and """[DRAFT]""" are the same list [DRAFT] as the unquoted form. A list on @= or == of a string fails. On the live Server (isolated stack, this branch):

Filter Result
title @=* "[DRAFT]" 400
title @=* """[DRAFT]""" 400
title == "[DRAFT]" 400
title @=* "[DRAFT" 200, [DRAFT] and [DRAFT] plan
title @= "[DRAFT] plan" 200, [DRAFT] plan
title ^^ ["[DRAFT]"] 200, [DRAFT]
title ^^* ["[draft]"] 200, [DRAFT]
title !^^ ["[DRAFT]"] 200, the other rows

For Equals and Not Equals, the list form ^^ ["[DRAFT]"] gives the same rows. Contains, Starts With, and Ends With have no form. The filter builder refuses the value for each operator, so that one rule has one message. A fix in QueryKit is to skip the list check when rightIsQuotedLiteral is true. The test a_whole_text_value_in_brackets_is_a_list_to_querykit pins the limit. It fails when QueryKit can hold the value.

Scope

  • A text value with a fault cannot be filtered. The user can remove the end quote or the end bracket and use Contains, which the control selects by default.
  • validateFilterState does not report a fault. The controls refuse it, and toQueryKitString leaves it out.

Blast Radius

  • Each text value and each multiselect value in a QueryKit string is now quoted. The Server reads each of them as text. If a template user's code relied on an unquoted null, or on a property name in a text filter, that filter now finds a text match.
  • toQueryKitString leaves out a filter with a fault, and it leaves out empty parts. Before, an empty multiselect gave a string such as a && . In an AND, a left-out filter widens the result. In an OR, it narrows it. The badge says that the filter is not used.

Verification

Each round has a failing test commit before its fix. This round: bf17860 (tests), 045fc07 (fix).

  • The end quote (earlier round, recipe edge-quotes.mjs, workshops with the titles "Paul", Paul, Pauline, "Quoted" title, Ends with quote", and Say "hi" now). Before (the controls of 175a1e4): the dialog took "Paul" with no message, and the filter it wrote had lost the quotes. After: Equals "Paul", Starts With "Quoted, and Contains quote" are refused with the message. Contains Quoted" title finds 1 row, Say "hi" now 1, Equals Paul 1, and Contains Paul 3, each with status 200. A component test watches the DOM while the user types Say "hi" now and proves that no alert is added.

  • The click on Cancel. Before: the Playwright test closes the dialog with one mouse click on Cancel after a quote at the end failed with "expect(locator).toBeHidden() failed. Received: visible" in each of the 3 time zone projects, and the component test takes one mouse click on Cancel after a quote at the end failed with "expected vi.fn() to be called once, but got 0 times". After: both pass. Live, Cancel stays at y 485.5 when the mouse button goes down (before the fix it went to 509.5), and the dialog closes after one click.

  • The crash. Before: toQueryKitString threw for "John". After: the converter tests and filter-builder.test.tsx show that the filter is left out and its badge says why. Live: a temporary preset with "John", [DRAFT], and Jane gives firstName == "Jane", the page does not crash, and both badges show the message (preset-not-used.png). Edit on the "John" badge shows the message at once, and after the fix of the value the string is firstName == "John" || firstName == "Jane".

  • The brackets. Before: the dialog took [DRAFT], and the Server gave 400. After: the dialog refuses it with the message (brackets-refused.png). [DRAFT] plan is added and finds its row with 200. The integration test a_filter_that_the_filter_builder_writes_finds_its_text now includes title ^^ ["[DRAFT]"].

  • At 320 px the badge message wraps under the badge, and the page has no horizontal scroll.

  • Gates on 045fc07: dotnet build FullstackTemplate.slnx with 0 warnings, WorkshopListQueryTests (21 passed), pnpm install --frozen-lockfile, pnpm lint, pnpm test (407 passed before the last test was added; the filter builder suite is 72 passed after), pnpm test:e2e (551 passed, 4 skipped), and pnpm build. The full dotnet test runs in CI. This round changed one .NET test file and no .NET code.

A text value with a quote, a hyphen, a dot, or the word null gives a
filter that the Server cannot read. The tests give the literal that the
Server reads, and the integration test proves that the Server finds the
row for each literal.
convertTextFilter quoted a value only when it had a space, so a value
with a quote, a hyphen, or a dot gave a 400, and the text null matched
no value. Each text and multiselect value now goes in quotes. A value
with a quote goes in a raw literal whose delimiter is longer than each
run of quotes in the value, because QueryKit has no escape in a quoted
value. QueryKit cannot keep a quote at the start or the end of a value,
so the converter removes those quotes.

Closes #363
A value of only quotes became an empty filter that matched each row,
and a value such as "Paul" showed its quotes in the badge but not in
the query. The text control now saves the text between the quotes at
the ends, and it cannot add a value of only quotes.
@pdevito3

pdevito3 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner Author

Review findings that stay open (independent thermo-nuclear review, two rounds, no high or medium left):

  • Low. A FilterState that code builds with a value of only quotes still gives title @=* "", which matches each row. Only the text control refuses it. Reason: no caller in the template builds such a state, and a preset is code that its author tests.
  • Low. The text control trims before it removes the end quotes, so " Paul " keeps its inner spaces. Reason: spaces inside quotes are the literal meaning of the input.
  • Low. The integration cases are hand copies of the converter output, not a shared fixture. Reason: the strings are short, and each side has its own test. A shared fixture across Vitest and TUnit is more machinery than these cases need.
  • Low. The functional test is in a new text-filter.spec.ts, not in filter-demo.spec.ts. Reason: open PR fix: close the low follow-ups of the checks of #335, #342, #340, and #343 #357 edits filter-demo.spec.ts.

Update after round 2 (045fc07): the first item is gone. A value of only quotes is a value with an end quote, so toQueryKitString leaves that filter out and its badge says that it is not used.

QueryKit cannot hold a quote at the start or the end of a text value. The
filter builder dropped it with no notice, so the list showed other rows.
QueryKit cannot hold a quote at the start or the end of a text value, so
the filter builder removed it and the list showed other rows. The text
and multiselect controls now refuse such a value with an inline message
that names the fault and the fix, and the converter throws for a state
that code builds.
@pdevito3 pdevito3 changed the title fix(frontend): quote each text value of a QueryKit filter fix(frontend): quote each text value of a QueryKit filter, and refuse a value with a quote at an end Oct 29, 2026
@pdevito3

pdevito3 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner Author

Open low findings from the fix round reviews. The owner asked to leave the low findings for now, so this PR fixes only the ones that a later fix made go away.

Correction to the first version of this list. Item 6 said that the dialog closes after a click on Cancel with a trailing quote in the field. That was false. The blur showed the alert, the alert moved Cancel 24 px down under the pointer, and the click missed. The dialog stayed open. Round 2 (045fc07) fixes it as a real fault, with a failing component test and a failing Playwright test before the fix.

Items from the first round:

  1. validateFilterState does not report a value with a fault. Only the controls and toQueryKitString refuse it. Still open.
  2. The multiselect shows the label of an option that a developer configured with an end quote. The user cannot fix that option. Only the developer can. Still open.
  3. The list of options in the multiselect message uses commas with no "and". Intl.ListFormat would read better. Still open.
  4. Add Filter went disabled and then enabled while the user typed Say ". Gone: Add Filter is now enabled for each value that is not empty.
  5. Add Filter stayed disabled after the user removed the first quote of "Paul". Gone, for the same reason.
  6. A click on Cancel with a trailing quote did not close the dialog (see the correction above). Fixed in 045fc07. The message now shows on a submit attempt, not on a blur.
  7. An initial filter with a fault showed no message until a blur. Fixed: the dialog shows the message at once when it edits such a filter.
  8. No test covered the message after a click on Add Filter for a trailing quote. Fixed: text-filter.test.tsx covers the click and the edit cases.

New items from the round 2 review:

  1. The badge reads the value as it is stored, and the dialog trims it when the user submits. A preset value such as "John" is not the same text in the two places.
  2. A multiselect list item with spaces around its quotes, such as "a", is not trimmed before the check.
  3. A screen reader does not announce the "not used" message of a preset badge when the preset loads, and it does not announce the dialog message again on a second submit with the same fault.
  4. The badge of a multiselect filter with a fault says "change the value", and the dialog says "Clear the option". An option with a fault that the developer configured cannot be cleared by the user.
  5. The Playwright tests are on the example filter demo page, which remove-examples.cs deletes. The component test of the Cancel click stays.
  6. A left-out filter widens the result in an AND and narrows it in an OR. The badge says that the filter is not used.

@pdevito3
pdevito3 merged commit aa00e8b into main Oct 29, 2026
36 of 37 checks passed
@pdevito3
pdevito3 deleted the fix/querykit-filters branch October 29, 2026 23:23
pdevito3 added a commit that referenced this pull request Nov 1, 2026
… a value with a quote at an end (#372)

* test(frontend): pin the QueryKit literal of a text filter with a quote

A text value with a quote, a hyphen, a dot, or the word null gives a
filter that the Server cannot read. The tests give the literal that the
Server reads, and the integration test proves that the Server finds the
row for each literal.

* fix(frontend): quote each text value of a QueryKit filter

convertTextFilter quoted a value only when it had a space, so a value
with a quote, a hyphen, or a dot gave a 400, and the text null matched
no value. Each text and multiselect value now goes in quotes. A value
with a quote goes in a raw literal whose delimiter is longer than each
run of quotes in the value, because QueryKit has no escape in a quoted
value. QueryKit cannot keep a quote at the start or the end of a value,
so the converter removes those quotes.

Closes #363

* fix(frontend): keep the quotes at the ends out of a text filter value

A value of only quotes became an empty filter that matched each row,
and a value such as "Paul" showed its quotes in the badge but not in
the query. The text control now saves the text between the quotes at
the ends, and it cannot add a value of only quotes.

* refactor(frontend): drop comments that repeat the code

* test(frontend): refuse a filter value with a quote at an end

QueryKit cannot hold a quote at the start or the end of a text value. The
filter builder dropped it with no notice, so the list showed other rows.

* fix(frontend): refuse a filter value with a quote at an end

QueryKit cannot hold a quote at the start or the end of a text value, so
the filter builder removed it and the list showed other rows. The text
and multiselect controls now refuse such a value with an inline message
that names the fault and the fix, and the converter throws for a state
that code builds.

* test(frontend): show the end quote message only when the user is done typing

* fix(frontend): show the end quote message only when the user is done typing

* test(frontend): a click on Cancel after an end quote, a value in brackets, and a filter state that QueryKit cannot hold

* fix(frontend): keep the dialog buttons in place after an end quote, refuse a value in brackets, and leave out a filter that QueryKit cannot hold
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.

A text filter with a quote gets a 400 from QueryKit

1 participant