Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Expression] Do not transform NULL integer as 0 when concat #36521

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,8 @@ static QVariant fcnConcat( const QVariantList &values, const QgsExpressionContex
QString concat;
for ( const QVariant &value : values )
{
concat += QgsExpressionUtils::getStringValue( value, parent );
if ( !value.isNull() )
concat += QgsExpressionUtils::getStringValue( value, parent );
}
return concat;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3891,6 +3891,26 @@ class TestQgsExpression: public QObject
QCOMPARE( QgsExpression::replaceExpressionText( input, &context ), expected );
}

void testConcatNULLAttributeValue()
{
// Test that null integer values comming from provider are not transformed as 0
troopa81 marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/qgis/QGIS/issues/36112

QgsFields fields;
fields.append( QgsField( QStringLiteral( "foo" ), QVariant::Int ) );

QgsFeature f;
f.initAttributes( 1 );
f.setAttribute( 0, QVariant( QVariant::Int ) );
troopa81 marked this conversation as resolved.
Show resolved Hide resolved

QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext( f, fields );

QgsExpression exp( QStringLiteral( "concat('test', foo)" ) );
QVariant res = exp.evaluate( &context );
QCOMPARE( res.type(), QVariant::String );
QCOMPARE( res.toString(), "test" );
}

};

QGSTEST_MAIN( TestQgsExpression )
Expand Down