Browse Source

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 ``.
pull/8/head
Anton Tarasenko 4 years ago
parent
commit
2004efc66f
  1. 22
      sources/Commands/CommandParser.uc
  2. 4
      sources/Commands/Tests/TEST_Command.uc

22
sources/Commands/CommandParser.uc

@ -523,9 +523,25 @@ private final function bool ParseTextValue(
AssociativeArray parsedParameters, AssociativeArray parsedParameters,
Command.Parameter expectedParameter) Command.Parameter expectedParameter)
{ {
local string textValue; local bool failedParsing;
commandParser.Skip().MStringS(textValue); local string textValue;
if (!commandParser.Ok()) { 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; return false;
} }
RecordParameter(parsedParameters, expectedParameter, RecordParameter(parsedParameters, expectedParameter,

4
sources/Commands/Tests/TEST_Command.uc

@ -353,7 +353,7 @@ protected static function SubTest_MockBQ1()
protected static function SubTest_MockBQ2() protected static function SubTest_MockBQ2()
{ {
local CommandCall result; local CommandCall result;
local DynamicArray subArray; local DynamicArray subArray;
local AssociativeArray options, subObject; local AssociativeArray options, subObject;
Issue("Cannot parse command queries with mixed-in options."); Issue("Cannot parse command queries with mixed-in options.");
@ -394,7 +394,7 @@ defaultproperties
queryAFailure2 = "simple fal" queryAFailure2 = "simple fal"
queryBSuccess1 = "[7, null] --values 1 3 5 2 4 text" 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 // long then same as short
queryBFailure1 = "[] 8 -tv 13" queryBFailure1 = "[] 8 -tv 13"
queryBFailure2 = "do 7 5 -sfV --forced yes" queryBFailure2 = "do 7 5 -sfV --forced yes"

Loading…
Cancel
Save