Skip to content

Commit

Permalink
An empty string parameter should not fallback to default value
Browse files Browse the repository at this point in the history
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 479106a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -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" ) );
Expand Down

0 comments on commit 479106a

Please sign in to comment.