Skip to content

fix(lookup): match a task reference and a search query literally - #268

Merged
ryanlewis merged 1 commit into
mainfrom
fix/issue-267-escape-lookup-search
Sep 10, 2026
Merged

ryanlewis merged 1 commit into
mainfrom
fix/issue-267-escape-lookup-search

Conversation

@ryanlewis

Copy link
Copy Markdown
Owner

Closes #267

Release note

A task reference and a search query now match literally — % and _ are characters to find, not wildcards — so things complete can no longer resolve to a task you did not name.

What changed

FindTasksByTitle and SearchTasks matched with LIKE and used the caller's text as the pattern, so _ stood for any character and % for any run of them. GetTask falls back to FindTasksByTitle and acts on a lookup that matches exactly one row, so things complete '20_30 review' could resolve to, and complete, a task called 20:30 review. #266 fixed the same gap for the list filters; this is the more dangerous half, because a write command acts on the result.

Both now escape the value and declare ESCAPE, from the constant #266 introduced. Substring matching is unchanged — the wildcards either side are the CLI's, and only the characters inside the value stop being pattern syntax. Matching stays case-insensitive.

Measured on the live database

command before after
search '50%' 45 rows 0
items whose title or notes contain the literal text 50% 0 0
search 'review' 129 129

My first regression tests were worthless, and that is the part worth reading

Both passed against the unfixed code. /code-review caught it by reverting the fix and running them. Two separate mistakes, both easy to repeat:

  • GetTask resolves an exact title before the LIKE is ever reached, so seeding the exact title under test never exercised the path.
  • LIKE wildcards act on the pattern, not on the stored value. I put the underscore in the seeded title and queried plain text, which tests nothing.

They are rebuilt around the real failure: resolve a reference that must miss, then resolve a substring that forces the LIKE path. I reverted tasks.go and confirmed they now fail, rather than taking the review's word:

GetTask("20_30 review") resolved to "t-colon"; no task is called that
GetTask("20_30 rev"): ambiguous task: "20_30 rev" matches 2 tasks
resolved to "t-colon" — a write would have hit a task the user never named
search 50%: got [s-pct s-fifty s-note], want [s-pct s-note]
search a_b: got [s-under s-axb], want [s-under]

Docs

Nothing documented changes, because wildcards were never offered for <task> or search. The README, the site's Searching and Inspecting sections, and the bundled skill now say the matching is literal, so the absence is stated rather than assumed.

make test and make lint are clean; hugo builds the site.

FindTasksByTitle and SearchTasks matched with LIKE and used the caller's text
as the pattern. So `_` stood for any character and `%` for any run of them in
a reference the user typed. GetTask falls back to FindTasksByTitle and acts on
a lookup that matches exactly one row, so `things complete '20_30 review'`
could resolve to, and complete, a task called "20:30 review" — a status write
on a task the user never named. #266 fixed the same gap for the list filters.

Both now escape the value and declare ESCAPE, from the constant #266
introduced. Substring matching is unchanged: the wildcards either side are the
CLI's, and only the characters inside the value stop being pattern syntax.
Matching stays case-insensitive, as it has always been.

On the live database `things search '50%'` returned 45 rows against no item
containing that text at all; it now returns none, and `search 'review'`
returns the same 129 either way.

The regression tests are the part worth reading. My first versions passed
against the unfixed code, which the review caught by reverting the fix and
running them. Both were vacuous for the same two reasons: GetTask resolves an
exact title before the LIKE is reached, so seeding the exact title never
exercised the path; and LIKE wildcards act on the pattern, not the stored
value, so putting the underscore in the seeded title tested nothing. They are
rebuilt around the real failure — resolve a reference that must miss, then a
substring that forces the LIKE path — and now fail against unfixed code with
pointed messages, which I confirmed by reverting.

Nothing documented changes: wildcards were never offered for `<task>` or
`search`. The README, the site and the bundled skill now say so.

Closes #267
@ryanlewis
ryanlewis merged commit 960d545 into main Sep 10, 2026
10 checks passed
@ryanlewis
ryanlewis deleted the fix/issue-267-escape-lookup-search branch September 10, 2026 15:13
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.

bug: title lookup and search use the reference as an unescaped LIKE pattern, so complete can act on the wrong task

1 participant