Skip to content

Commit

Permalink
Fix crash when no options are selected in a multiple-enum parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent a6b14a0 commit aeecda3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -158,6 +158,9 @@ QList<int> QgsProcessingParameters::parameterAsEnums( const QgsProcessingParamet
else
resultList << val;

if ( resultList.isEmpty() )
return QList< int >();

if ( ( !val.isValid() || !resultList.at( 0 ).isValid() ) && definition )
{
resultList.clear();
Expand Down
9 changes: 9 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -2693,6 +2693,11 @@ void TestQgsProcessing::parameterEnum()
iNumbers = QgsProcessingParameters::parameterAsEnums( def.get(), params, context );
QCOMPARE( iNumbers, QList<int>() << 0 << 2 );

// empty list
params.insert( "non_optional", QVariantList() );
iNumbers = QgsProcessingParameters::parameterAsEnums( def.get(), params, context );
QCOMPARE( iNumbers, QList<int>() );

QCOMPARE( def->valueAsPythonString( QVariantList() << 1 << 2, context ), QStringLiteral( "[1,2]" ) );
QCOMPARE( def->valueAsPythonString( QStringLiteral( "1,2" ), context ), QStringLiteral( "[1,2]" ) );

Expand Down Expand Up @@ -2760,6 +2765,10 @@ void TestQgsProcessing::parameterEnum()
params.insert( "optional", QVariant() );
iNumbers = QgsProcessingParameters::parameterAsEnums( def.get(), params, context );
QCOMPARE( iNumbers, QList<int>() << 1 << 2 );
// empty list
params.insert( "optional", QVariantList() );
iNumbers = QgsProcessingParameters::parameterAsEnums( def.get(), params, context );
QCOMPARE( iNumbers, QList<int>() );

code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##optional=optional enum multiple A;B;C 1,2" ) );
Expand Down

0 comments on commit aeecda3

Please sign in to comment.