Skip to content
Permalink
Browse files

Fix crash when no options are selected in a multiple-enum parameter

  • Loading branch information
nyalldawson committed Jun 27, 2017
1 parent a6b14a0 commit aeecda370761a54f6fc5a8e6d63f61ab1784f5b3
Showing with 12 additions and 0 deletions.
  1. +3 −0 src/core/processing/qgsprocessingparameters.cpp
  2. +9 −0 tests/src/core/testqgsprocessing.cpp
@@ -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();
@@ -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]" ) );

@@ -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" ) );

0 comments on commit aeecda3

Please sign in to comment.
You can’t perform that action at this time.