Skip to content
Permalink
Browse files

An empty string parameter should not fallback to default value

Since we need to allow empty strings to override defaults in
some circumstances
  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent d45215e commit 479106ad804677f9a1c7656fc240429ee6474cbf
Showing with 3 additions and 1 deletion.
  1. +1 −1 src/core/processing/qgsprocessingparameters.cpp
  2. +2 −0 tests/src/core/testqgsprocessing.cpp
@@ -41,7 +41,7 @@ QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameter
if ( val.canConvert<QgsProperty>() )
return val.value< QgsProperty >().valueAsString( context.expressionContext(), definition->defaultValue().toString() );

if ( !val.isValid() || val.toString().isEmpty() )
if ( !val.isValid() )
{
// fall back to default
val = definition->defaultValue();
@@ -2978,6 +2978,8 @@ void TestQgsProcessing::parameterString()

params.insert( "optional", QVariant() );
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ), QString( "default" ) );
params.insert( "optional", QString() ); //empty string should not result in default value
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ), QString() );

code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##optional=optional string default" ) );

0 comments on commit 479106a

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