Skip to content

Commit 978642a

Browse files
committed
Allow + for string concat in QgsExpression
1 parent 0b213b6 commit 978642a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/core/qgsexpression.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,12 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression* parent, const Q
20812081
switch ( mOp )
20822082
{
20832083
case boPlus:
2084+
if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
2085+
{
2086+
QString sL = getStringValue( vL, parent ); ENSURE_NO_EVAL_ERROR;
2087+
QString sR = getStringValue( vR, parent ); ENSURE_NO_EVAL_ERROR;
2088+
return QVariant( sL + sR );
2089+
}
20842090
case boMinus:
20852091
case boMul:
20862092
case boDiv:

tests/src/core/testqgsexpression.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class TestQgsExpression: public QObject
223223
QTest::newRow( "regexp 3" ) << "'hello' ~ 'llo$'" << false << QVariant( 1 );
224224

225225
// concatenation
226+
QTest::newRow( "concat with plus" ) << "'a' + 'b'" << false << QVariant( "ab" );
226227
QTest::newRow( "concat" ) << "'a' || 'b'" << false << QVariant( "ab" );
227228
QTest::newRow( "concat with int" ) << "'a' || 1" << false << QVariant( "a1" );
228229
QTest::newRow( "concat with int" ) << "2 || 'b'" << false << QVariant( "2b" );

0 commit comments

Comments
 (0)