ColumnTypeString: Only input of single DOM token should be attempted to be evaluated

Attribute names are often words from natural language (such as start,
end or entry). The ColumnTypeString supports resolving DOM references,
such that task commands like 'task add proj:3.proj' work.

However, the current implementation of the ColumnTypeString::modify
only looks at the first token to determine whether the input is a DOM
reference or not. This mischaracterizes inputs like 'task add
"description:start something"', where the first token of the attribute
value looks like a DOM reference (the 'start' attribute), but is in
fact, a part of larger string.

Since all DOM references are single tokens, only interpret the input as
a possible DOM reference if and only if one token was found.

Closes #1908.
This commit is contained in:
Tomas Babej 2021-01-30 18:27:39 -05:00
parent fac48e5e93
commit 64b6784f69

View file

@ -58,7 +58,12 @@ void ColumnTypeString::modify (Task& task, const std::string& value)
std::string domRef; std::string domRef;
Lexer::Type type; Lexer::Type type;
if (lexer.token (domRef, type) && if (lexer.token (domRef, type) &&
type == Lexer::Type::dom) type == Lexer::Type::dom &&
// Ensure 'value' contains only the DOM reference and no other tokens
// The lexer.token returns false for end-of-string.
// This works as long as all the DOM references we should support consist
// only of a single token.
lexer.token (domRef, type) == false)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);