Repository navigation
fix(frontend): quote each text value of a QueryKit filter, and refuse a value with a quote at an end - #372
Conversation
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.
|
Review findings that stay open (independent thermo-nuclear review, two rounds, no high or medium left):
Update after round 2 (045fc07): the first item is gone. A value of only quotes is a value with an end quote, so |
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.
|
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:
New items from the round 2 review:
|
…kets, and a filter state that QueryKit cannot hold
…efuse a value in brackets, and leave out a filter that QueryKit cannot hold
… 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
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
nullfound the rows with no value. Closes #363.What changed
querykit-converter.tsputs 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-text.tsnames them asTextValueFault: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.aria-invalidandaria-describedby, and the filter is not added.FilterStatefrom a preset or an initial state can hold a value with a fault.toQueryKitStringdoes 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,toQueryKitStringthrew in render, and the demo page showed "Something went wrong!".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 aParsingException, the value without its end quote (""""Paul""""findsPaul), or no rows. InQueryKit/FilterParser.cs:RawStringLiteralParsertakes 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.
DoubleQuoteParserandRawStringLiteralParserreturn the content without its quotes, andRightSideValue.IsQuotedLiteralrecords that it was quoted. ThenCreateRightExprFromTypechecksright.StartsWith("[") && right.EndsWith("]")and reads the value as a list, also whenrightIsQuotedLiteralis 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):title @=* "[DRAFT]"title @=* """[DRAFT]"""title == "[DRAFT]"title @=* "[DRAFT"[DRAFT]and[DRAFT] plantitle @= "[DRAFT] plan"[DRAFT] plantitle ^^ ["[DRAFT]"][DRAFT]title ^^* ["[draft]"][DRAFT]title !^^ ["[DRAFT]"]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 whenrightIsQuotedLiteralis true. The testa_whole_text_value_in_brackets_is_a_list_to_querykitpins the limit. It fails when QueryKit can hold the value.Scope
validateFilterStatedoes not report a fault. The controls refuse it, andtoQueryKitStringleaves it out.Blast Radius
null, or on a property name in a text filter, that filter now finds a text match.toQueryKitStringleaves out a filter with a fault, and it leaves out empty parts. Before, an empty multiselect gave a string such asa &&. 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", andSay "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 Containsquote"are refused with the message. ContainsQuoted" titlefinds 1 row,Say "hi" now1, EqualsPaul1, and ContainsPaul3, each with status 200. A component test watches the DOM while the user typesSay "hi" nowand 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 endfailed with "expect(locator).toBeHidden() failed. Received: visible" in each of the 3 time zone projects, and the component testtakes one mouse click on Cancel after a quote at the endfailed 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:
toQueryKitStringthrew for"John". After: the converter tests andfilter-builder.test.tsxshow that the filter is left out and its badge says why. Live: a temporary preset with"John",[DRAFT], andJanegivesfirstName == "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 isfirstName == "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] planis added and finds its row with 200. The integration testa_filter_that_the_filter_builder_writes_finds_its_textnow includestitle ^^ ["[DRAFT]"].At 320 px the badge message wraps under the badge, and the page has no horizontal scroll.
Gates on 045fc07:
dotnet build FullstackTemplate.slnxwith 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), andpnpm build. The fulldotnet testruns in CI. This round changed one .NET test file and no .NET code.