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. 20
      sources/Commands/CommandParser.uc
  2. 2
      sources/Commands/Tests/TEST_Command.uc

20
sources/Commands/CommandParser.uc

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

2
sources/Commands/Tests/TEST_Command.uc

@ -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