Skip to content
Permalink
Browse files

[processing] Safename for scope variable shouldn't contain "."

Fixes #36377

(cherry picked from commit 08542ef)
  • Loading branch information
luipir authored and nyalldawson committed Jun 19, 2020
1 parent 30cd6f0 commit 6101c2e9fa0b378f39ea96313e235a0eb65eb480
@@ -713,7 +713,7 @@ QMap<QString, QgsProcessingModelAlgorithm::VariableDefinition> QgsProcessingMode
auto safeName = []( const QString & name )->QString
{
QString s = name;
return s.replace( QRegularExpression( QStringLiteral( "[\\s'\"\\(\\):]" ) ), QStringLiteral( "_" ) );
return s.replace( QRegularExpression( QStringLiteral( "[\\s'\"\\(\\):\\.]" ) ), QStringLiteral( "_" ) );
};

// "static"/single value sources
@@ -7876,6 +7876,20 @@ void TestQgsProcessing::modelExecution()
QGSCOMPARENEAR( variables.value( "SOURCE_LAYER_maxx" ).value.toDouble(), -83.3333, 0.001 );
QGSCOMPARENEAR( variables.value( "SOURCE_LAYER_maxy" ).value.toDouble(), 46.8719, 0.001 );

// test safe name of the child alg parameter as source to another algoritmn
// parameter name should have [\s ' ( ) : .] chars changed to "_" (regexp [\\s'\"\\(\\):\.])
// this case is esecially important in case of grass algs where name algorithm contains "."
// name of the variable is get from childDescription or childId. Refs https://github.com/qgis/QGIS/issues/36377
QgsProcessingModelChildAlgorithm &cx1 = model2.childAlgorithm( "cx1" );
QString oldDescription = cx1.description();
cx1.setDescription( "cx '():.1" );
variables = model2.variablesForChildAlgorithm( "cx3", context );
QVERIFY( !variables.contains( "cx1_OUTPUT" ) );
QVERIFY( !variables.contains( "cx '():.1_OUTPUT" ) );
QVERIFY( variables.contains( "cx______1_OUTPUT" ) );
cx1.setDescription( oldDescription ); // set descrin back to avoid fail of following tests

// test model to python conversion
model2.setName( QStringLiteral( "2my model" ) );
model2.childAlgorithm( "cx1" ).modelOutput( QStringLiteral( "MODEL_OUT_LAYER" ) ).setDescription( "my model output" );
model2.updateDestinationParameters();

0 comments on commit 6101c2e

Please sign in to comment.
You can’t perform that action at this time.