From 2004efc66f0ffa07dfa85c99514ea68ec400066f Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sun, 7 Mar 2021 20:28:02 +0700 Subject: [PATCH] Change how empty `Text` parameters are treated Before even no input would be interpreted as an empty `Text` parameter, but now one has to explicitly as "", '' or ``. --- sources/Commands/CommandParser.uc | 22 +++++++++++++++++++--- sources/Commands/Tests/TEST_Command.uc | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sources/Commands/CommandParser.uc b/sources/Commands/CommandParser.uc index 59c2ea3..3a8dd38 100644 --- a/sources/Commands/CommandParser.uc +++ b/sources/Commands/CommandParser.uc @@ -523,9 +523,25 @@ private final function bool ParseTextValue( AssociativeArray parsedParameters, Command.Parameter expectedParameter) { - local string textValue; - commandParser.Skip().MStringS(textValue); - if (!commandParser.Ok()) { + local bool failedParsing; + local string textValue; + local parser.ParserState initialState; + // TODO: use parsing methods into `Text` + // (needs some work for reading formatting `string`s from `Text` objects) + initialState = commandParser.Skip().GetCurrentState(); + // Try manually parsing as a string literal first, since then we will + // allow empty `textValue` as a result + commandParser.MStringLiteralS(textValue); + failedParsing = !commandParser.Ok(); + // Otherwise - empty values are not allowed + if (failedParsing) + { + commandParser.RestoreState(initialState).MStringS(textValue); + failedParsing = (!commandParser.Ok() || textValue == ""); + } + if (failedParsing) + { + commandParser.Fail(); return false; } RecordParameter(parsedParameters, expectedParameter, diff --git a/sources/Commands/Tests/TEST_Command.uc b/sources/Commands/Tests/TEST_Command.uc index 1de2dfc..ac4ffcd 100644 --- a/sources/Commands/Tests/TEST_Command.uc +++ b/sources/Commands/Tests/TEST_Command.uc @@ -353,7 +353,7 @@ protected static function SubTest_MockBQ1() protected static function SubTest_MockBQ2() { - local CommandCall result; + local CommandCall result; local DynamicArray subArray; local AssociativeArray options, subObject; Issue("Cannot parse command queries with mixed-in options."); @@ -394,7 +394,7 @@ defaultproperties queryAFailure2 = "simple fal" queryBSuccess1 = "[7, null] --values 1 3 5 2 4 text" - queryBSuccess2 = "do --type \"value\" -va 8 -sV --forced -T" + queryBSuccess2 = "do --type \"value\" -va 8 -sV --forced -T \"\" " // long then same as short queryBFailure1 = "[] 8 -tv 13" queryBFailure2 = "do 7 5 -sfV --forced yes"