Repository navigation
feat(filters): choose case sensitivity for postgres text matches - #1173
umairnaeem0309 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
| }); | ||
|
|
||
| it("escapes wildcards, quotes and the escape character identically in both modes", () => { | ||
| const value = "100%_off!\sale O'Brien"; |
There was a problem hiding this comment.
SUGGESTION: \s in these string literals is not a backslash
In a JS string literal "\s" is just "s" (an unnecessary escape), so this value is actually 100%_off!sale O'Brien and no backslash is exercised. The expectation on line 728 only passes because !!\s collapses to !!s the same way. The test title promises to cover the escape character and quotes, so an accidental \s reads as if a backslash case were covered when it is not. Either drop the stray backslash or use \\ if a literal backslash is intended (note that postgres does not double it, unlike MySQL).
| const value = "100%_off!\sale O'Brien"; | |
| const value = "100%_off!sale O'Brien"; |
(Line 728 would need the matching change: "name LIKE '%100!%!_off!!sale O''Brien%' ESCAPE '!'".)
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Notes
Files Reviewed (17 files)
Previous Review Summaries (2 snapshots, latest commit 17ead8a)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 17ead8a)Status: 1 Issue Found | Recommendation: Merge (optional test-data cleanup) Overview
Issue Details (click to expand)SUGGESTION
Notes
Fix these issues in Kilo Cloud Files Reviewed (17 files)
Previous review (commit 1c59a39)Status: 1 Issue Found | Recommendation: Merge (optional test-data cleanup) Overview
Issue Details (click to expand)SUGGESTION
Notes
Fix these issues in Kilo Cloud Files Reviewed (16 files)
Reviewed by claude-sonnet-5.5 · Input: 258 · Output: 1.8K · Cached: 296.3K Review guidance: REVIEW.md from base branch |
1c59a39 to
17ead8a
Compare
Literal text filters always built LIKE, so a PostgreSQL connection had no way to ask for a case-insensitive match. A filter row now carries an optional matchCase flag: true (the default, including for rows saved before this change) keeps LIKE, false emits ILIKE. Only the postgres dialect acts on it. Every other dialect ignores the flag and produces byte-identical SQL, which is asserted per dialect, and the toggle is hidden where ILIKE cannot run. Plugin drivers are covered through sql_dialect, matching isPostgresDialect's existing capability reading. The pattern is escaped once and only the keyword changes, so wildcards, quotes and the ESCAPE '!' clause behave the same in both modes.
17ead8a to
5128828
Compare
|
Thanks @kilo-code-bot[bot] — the I also took the Re-ran on the pushed commit: 380 tests exit 0, |
debba
left a comment
There was a problem hiding this comment.
Thanks for this, and welcome! I really liked the escaping test that checks the case-insensitive SQL is exactly the case-sensitive SQL with LIKE swapped for ILIKE, so the two modes can't drift apart. It's also great to see the plugin side handled properly: the toggle is gated on isPostgresDialect(activeCapabilities ?? activeDriver), and there are tests with a capabilities object and a plugin manifest under a different id, which is exactly what .rules/plugins.md asks for.
Since this is your first PR here: if you'd like to hang out with us, we'd be happy to see you on Discord: https://discord.com/invite/K2hmhfHRSt
The tests pass on the branch (259 across filterBar, FilterRow, TableToolbar, cellValueFilter and the i18n test), and lint and typecheck are clean. There's one bug I'd like fixed before merging, though:
Flipping Aa on an applied filter doesn't reset the "Applied" state. The toggle calls onChange({ ...filter, matchCase: !matchCase }), but handleFilterChange in TableToolbar.tsx decides whether to call onResetApplied by comparing only column, operator, value and value2. Since matchCase isn't in that comparison, the change is treated like a simple enable/disable toggle. Steps to see it: apply name contains ada, then click Aa without re-applying. The row button stays green "Applied" while the grid still shows the old LIKE/ILIKE result. Adding isMatchCaseEnabled(prev) === isMatchCaseEnabled(updated) to that check, plus a test, should be enough.
A small nit while you're there: FilterRow.tsx hardcodes the three text-match operators, while filterBar.ts already has the LikeMatchMode type for them. A small helper next to it would keep the list in one place.
|
Thanks a lot for the work on this, and sorry for how it turned out. #1164 got picked up again in #1252, which also covers the Applied state issue from my review here, and it has now been merged, so I'm closing this one as superseded. I really appreciate the time you put into it, and I hope to see more PRs from you! |
Closes #1164.
What changed
Literal text filters (
contains,starts with,ends with) always generatedLIKE, so a PostgreSQL connection had no way to ask for a case-insensitive match. A filter row now carries an optionalmatchCaseflag:true(default)LIKELIKEfalseILIKELIKE(flag ignored)The default is
truefor every row, including rows saved before this change, so nothing existing starts matching differently.src/utils/filterBar.ts—matchCase?: booleanonStructuredFilter,isMatchCaseEnabled()helper,buildLiteralLikeClause()picks the keyword. Dialect comes fromisPostgresDialect, so it is capability-driven, not id-driven.src/components/ui/FilterRow.tsx— anAatoggle next to the value field, rendered only for the three literal text operators. It exposes state witharia-pressed, has a translatedaria-label, a hint ontitle, and the standardfocus-visible:outline-focusring.src/components/ui/TableToolbar.tsx— computessupportsMatchCase={isPostgresDialect(quotingDriver)}fromactiveCapabilities ?? activeDriver.Escaping is untouched: the pattern is escaped once (
!→!!,%→!%,_→!_, quotes doubled) and only the keyword changes, withESCAPE '!'kept in both modes. The new tests assert the case-insensitive literal is the case-sensitive one withLIKEswapped forILIKE, so escaping cannot drift between modes.Dialect and plugin behaviour
postgres— toggle shown,ILIKEavailable.sql_dialect: "postgres"— toggle shown,ILIKEavailable. Verified with a fullPluginManifestfixture (also covers a plugin id that is notpostgres), consistent with.rules/plugins.md.sql_dialect— treated as postgres, matching the manifest schema default thatisPostgresDialectuses.mysql,mariadb,sqlite,mssql,oracle,generic— toggle hidden, and the builder is asserted to return byte-identical SQL with the flag on and off, so no existing filter changes.MySQL/MariaDB backslash doubling is unaffected and still covered by the existing tests in both modes.
Testing
New coverage:
tests/utils/filterBar.test.ts— default staysLIKE; a filter round-tripped from JSON without the field staysLIKE;ILIKEfor the builtin driver and for a plugin capabilities object + full manifest; escaping identical in both modes; per-dialect no-op assertion for the six non-postgres dialects; the setting applies per row inside a combined clause; other operators untouched.tests/components/ui/FilterRow.test.tsx— toggle offered only on postgres, reflects the stored value, flipsonChangewithout touching the value, and is absent whensupportsMatchCaseis false or the operator is not a text match.tests/i18n/filterMatchCase.test.ts— all 11 locales cover both strings, and the hint keeps namingILIKE.Mutation-checked, so the tests are not vacuous:
LIKEalways → 4 failuresILIKEeverywhere) → 6 failuresReview follow-up (thanks @kilo-code-bot[bot]): the escaping fixture used a
\sliteral, which JavaScript reads as plains, so it never actually held a backslash. It now carries a real one, andexpect(value).toContain("\\")asserts the fixture itself, so the test name and the data cannot drift apart again.Commands run (exit status captured directly, not through a pipe):
tests/i18n/filterMatchCase.test.tslives undertests/i18n/next to the existing per-feature locale tests rather than mirroringsrc/, following that directory's established pattern.Notes
impact()pass; the MCP tools were not available in my environment, so call sites were enumerated directly instead.buildSingleFilterClausehas one caller (TableToolbar.tsx).buildLiteralLikeClausehas two:buildSingleFilterClausehere, andbuildCellValueFilterClause(src/utils/cellValueFilter.ts:47, the filter-by-cell-value path), which passes four arguments and therefore keeps emittingLIKE— that path has no case option in its UI and is deliberately unchanged in this PR.buildStructuredFilterClauseis called fromTableToolbar.tsxand frombuildValuePickerWherein the same module. The newStructuredFilterfield and the newbuildLiteralLikeClauseparameter are optional, so no signature breaks.cargo testwas not run; no Rust code changed.