Skip to content

Commit e470b6c

Browse files
committed
Fix newline characters break embedded expressions
Fixes #21471 (cherry picked from commit daeb3d8)
1 parent 089e418 commit e470b6c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/core/expression/qgsexpression.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
474474
int index = 0;
475475
while ( index < action.size() )
476476
{
477-
static const QRegularExpression sRegEx{ QStringLiteral( "\\[%(.*?)%\\]" ) };
477+
static const QRegularExpression sRegEx{ QStringLiteral( "\\[%(.*?)%\\]" ), QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption };
478478

479479
const QRegularExpressionMatch match = sRegEx.match( action, index );
480480
if ( !match.hasMatch() )

tests/src/core/testqgsexpression.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,8 @@ class TestQgsExpression: public QObject
34133413
QTest::newRow( "multiple exp" ) << "some [% 3+ 7 %] text [% 1 + 2 %]" << "some 10 text 3";
34143414
QTest::newRow( "complex" ) << "some [%map('a', 1, 'b', 2)['a']%] text [%map('a', 1, 'b', 2)['b']%]" << "some 1 text 2";
34153415
QTest::newRow( "complex2" ) << "some [% 'my text]' %] text" << "some my text] text";
3416+
QTest::newRow( "newline 1" ) << "some \n [% 1 + 2 %] \n text" << "some \n 3 \n text";
3417+
QTest::newRow( "newline 2" ) << "some [% \n 1 \n + \n 2 %] \n text" << "some 3 \n text";
34163418
}
34173419

34183420
void testReplaceExpressionText()

0 commit comments

Comments
 (0)