Repository navigation
Conversation
A quoted filter was one command-line word, so context define stored it as a write context and later prepended "or" onto new task descriptions. Co-authored-by: Cursor <cursoragent@cursor.com>
djmitche
left a comment
There was a problem hiding this comment.
The command-line lexer and parser are pretty complex and nobody working on the project understands them at this point. So, I'm a little worried that this fix breaks something else which people might be relying on.
Please rewrite the PR description to include more background and less of the jargony short sentences. This is a better place to describe what "miscellaneous" is and how a different kind of lexing works differently.
As I understand it, the underlying issue is that the definition given to task context define is used, as a series of tokens, in different contexts and can mean different things in those contexts. Can the fix operate at that level, too?
| std::vector<A2> lexedArgs = Context::getContext().cli2.getMiscellaneous(); | ||
| // Lex the definition that will be stored. A quoted filter arrives as one | ||
| // command-line word, so getMiscellaneous() hides operators inside it, but | ||
| // those operators are applied when the write context is used. |
There was a problem hiding this comment.
This is a confusing AIism where the comment says what it doesn't do -- in this case, it describes getMiscellaenous which is not called here.
The comment now says the definition is lexed before the write-context check. Co-authored-by: Cursor <cursoragent@cursor.com>
Closes #3760
The bug
task context define <name> <filter>saves the filter twice.context.<name>.readis the filter used by reports.context.<name>.writeholds default values for new tasks: while the context is active,task addsplices that same text into its command line as if you had typed it. Only some filters make sense that way.+homeorproject:Homecan become tags and attributes on a new task.+home or +work, a tag exclusion like-work, or a modifier likedue.before:todaycannot. Before saving the write value,defineContextlooks for those three things, and if it finds one it prints a warning and saves the context as read only.That check worked when the filter was typed as separate words, but not when the same filter was quoted, as in the issue:
Without the quotes the same command already warned and saved the context as read only.
Why it happened
Taskwarrior splits the command line in two different ways.
CLI2::lexArguments). A word that holds a single token, likeoror+home, gets its type (operator, tag, attribute). A word that holds several tokens, like the quoted+personal or +home or +work, is kept whole as one plain word. The one exception is a quoted word that starts with an attribute such asdue.before:today, which keeps that type. That is why quoted"due.before:today +next"was already read only, while the quotedorfilter, which starts with a tag, was not. Every argument after thecontextcommand, includingdefineand the context name, is tagged "miscellaneous", which just means "not a filter and not a modification, the command reads these words itself".CLI2::addFilterfor read,CLI2::addModificationsfor write), the saved string is run through the lexer as one string, so every token is seen, including theorinside the quotes.The old check used the miscellaneous arguments from step 1. For a quoted filter it saw one plain word and no
or, so it allowed the write context. Whentask addused it, step 2 split the same text and theortokens ended up in the description.What this change does
In
defineContext(src/commands/CmdContext.cpp), the write check now lexes the exact string that will be saved, with the sameLexerloop thatCLI2::addModificationsruns when the write context is applied. So to your question, yes: the check now works on the same series of tokens thattask addwill later get from the saved text, instead of on the shell words. The rules invalidateWriteContextare unchanged: rejector, tag exclusions, and modifiers other thanisandequals.What does not change
CLI2::lexArguments,addFilterandaddModificationsare untouched, so filtering with a context and applying an existing write context behave as before..writecan change.task context define, andvalidateWriteContexthas no other caller. After this changeCLI2::getMiscellaneoushas no callers left. I left it in place..taskrcare not re-checked or removed.What can change for users
A definition is now saved as read only when its quoted text contains
or, a tag exclusion or a disallowed modifier. In every such case the unquoted form of the same filter was already read only, and keeping the write value would have put that text into new tasks. One case I checked besides the issue: quoted"due:today -work"used to save a write context and is now read only, likedue:today -workwithout quotes. The other change goes the opposite way. The old check also looked at the context name, sotask context define or +homeused to be read only. Now only the definition is checked, so that command saves read and write, andtask addin that context applies+home.Checked by hand on Debug builds of
develop(c564bc3f) and this branch, unchanged before and after: quoted"project:Work +urgent", unquotedproject:Home, quoted"+personal"and quoted"+personal and +home"stay read and write. Quoted"due.before:today +next"and quoted"-work"stay read only.xoris still allowed in a write context, becausevalidateWriteContextonly rejectsor. That is the existing rule and this PR does not change it.How it was tested
test_context_define_quoted_or_is_not_a_write_contextintest/context.test.py. It failed before the change (Context 'mine' defined (read, write).) and passes after. It also checks thattask add this is a testkeeps the description as typed.ctest --test-dir build -R '^context\.test\.py$' --output-on-failurepasses, including the existing unquotedor, tag exclusion and modifier tests.ctest -j 8on a clean Debug build of this branch: 179 of 179 passed. On the first parallel runview_test.cppfailed once and then passed on every rerun, alone and in parallel. It does not touch context code.Prepared with Cursor assistance.