Skip to content

Commit

Permalink
[processing] Safename for scope variable shouldn't contain "."
Browse files Browse the repository at this point in the history
Fixes #36377

(cherry picked from commit 08542ef)
  • Loading branch information
luipir authored and nyalldawson committed Jun 19, 2020
1 parent 30cd6f0 commit 6101c2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/processing/models/qgsprocessingmodelalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6101c2e

Please sign in to comment.