Added string length check when checking switch params

Fixes #1051
This commit is contained in:
Leira Hua 2016-12-24 17:42:31 -08:00
parent 3a6167ae62
commit f79018cffd
2 changed files with 3 additions and 3 deletions

View File

@ -421,7 +421,7 @@ void CommandManager::execute_single_command(CommandParameters params,
if (params.empty())
return;
ConstArrayView<String> param_view(params.begin()+1, params.end());
ParameterList param_view(params.begin()+1, params.end());
auto command_it = find_command(context, params[0]);
if (command_it == m_commands.end())
throw command_not_found(params[0]);

View File

@ -23,7 +23,7 @@ ParametersParser::ParametersParser(ParameterList params,
{
if (not only_pos and params[i] == "--")
only_pos = true;
else if (not only_pos and params[i][0_byte] == '-')
else if (not only_pos and params[i].length() > 0 and params[i][0_byte] == '-')
{
auto it = m_desc.switches.find(params[i].substr(1_byte));
if (it == m_desc.switches.end())
@ -36,7 +36,7 @@ ParametersParser::ParametersParser(ParameterList params,
throw missing_option_value(it->key);
}
}
else
else // positional
{
if (desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart)
only_pos = true;