From 4b37fea21fb064c947bb812875b67d01dde2024e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 1 Feb 2016 23:57:10 -0500 Subject: [PATCH] ColTypeString: Added validate() in ::modify --- ChangeLog | 1 + src/columns/ColTypeString.cpp | 44 +++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index a10f641d8..eea0aa2b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,7 @@ - TW-1705 Directories in .task/hooks should not be reported as invalid hooks (thanks to Tomas Babej). - TW-1714 Starting recurring task starts all recurrences (thanks to Robin Green). +- TW-1718 String UDA not passed through unchanged (thanks to Wim Schuermann). - TW-1719 Description cannot contain improper ordinals (thanks to Ben Boeckel). - TW-1720 CmdContext uses a mix of both throw and std::cout to convey errors (thanks to Paul Beckingham). diff --git a/src/columns/ColTypeString.cpp b/src/columns/ColTypeString.cpp index a15d919a6..bb89586da 100644 --- a/src/columns/ColTypeString.cpp +++ b/src/columns/ColTypeString.cpp @@ -64,31 +64,41 @@ void ColumnTypeString::render ( //////////////////////////////////////////////////////////////////////////////// void ColumnTypeString::modify (Task& task, const std::string& value) { - // Try to evaluate 'value'. It might work. - Variant evaluatedValue; - try + std::string label = " MODIFICATION "; + + // Only if it's a DOM ref, eval it first. + Lexer lexer (value); + std::string domRef; + Lexer::Type type; + if (lexer.token (domRef, type) && + type == Lexer::Type::dom) { Eval e; e.addSource (domSource); e.addSource (namedDates); contextTask = task; - e.evaluateInfixExpression (value, evaluatedValue); - } - catch (...) - { - evaluatedValue = Variant (value); - } - - std::string label = " MODIFICATION "; - std::string strValue = (std::string) evaluatedValue; - if (validate (strValue)) - { - context.debug (label + _name + " <-- '" + strValue + "' <-- '" + value + "'"); - task.set (_name, strValue); + Variant v; + e.evaluateInfixExpression (value, v); + std::string strValue = (std::string) v; + if (validate (strValue)) + { + task.set (_name, strValue); + context.debug (label + _name + " <-- '" + strValue + "' <-- '" + value + "'"); + } + else + throw format (STRING_INVALID_MOD, _name, value); } else - throw format (STRING_INVALID_MOD, _name, value); + { + if (validate (value)) + { + task.set (_name, value); + context.debug (label + _name + " <-- '" + value + "'"); + } + else + throw format (STRING_INVALID_MOD, _name, value); + } } ////////////////////////////////////////////////////////////////////////////////