mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-04 00:30:59 -05:00
[processing] Fix string escaping when converting models to python code
with expression parameters Fixes #32451
This commit is contained in:
parent
328f365b16
commit
e3eb4f54ab
@ -169,7 +169,7 @@ QString QgsProcessingModelChildParameterSource::asPythonCode( const QgsProcessin
|
||||
}
|
||||
|
||||
case Expression:
|
||||
return QStringLiteral( "QgsExpression('%1').evaluate()" ).arg( mExpression );
|
||||
return QStringLiteral( "QgsExpression(%1).evaluate()" ).arg( QgsProcessingUtils::stringToPythonLiteral( mExpression ) );
|
||||
|
||||
case ExpressionText:
|
||||
return mExpressionText;
|
||||
|
@ -6894,6 +6894,9 @@ void TestQgsProcessing::modelerAlgorithm()
|
||||
expSource.setExpression( "1+3" );
|
||||
QCOMPARE( expSource.expression(), QStringLiteral( "1+3" ) );
|
||||
QCOMPARE( expSource.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr, friendlyNames ), QStringLiteral( "QgsExpression('1+3').evaluate()" ) );
|
||||
expSource.setExpression( "'a' || 'b\\'c'" );
|
||||
QCOMPARE( expSource.expression(), QStringLiteral( "'a' || 'b\\'c'" ) );
|
||||
QCOMPARE( expSource.asPythonCode( QgsProcessing::PythonQgsProcessingAlgorithmSubclass, nullptr, friendlyNames ), QStringLiteral( "QgsExpression('\\'a\\' || \\'b\\\\\\'c\\'').evaluate()" ) );
|
||||
expSource = QgsProcessingModelChildParameterSource::fromStaticValue( 5 );
|
||||
// check that calling setExpression flips source to Expression
|
||||
QCOMPARE( expSource.source(), QgsProcessingModelChildParameterSource::StaticValue );
|
||||
|
Loading…
x
Reference in New Issue
Block a user