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"