Skip to content

Commit

Permalink
[processing] Fix invalid filenames are used for temporary files
Browse files Browse the repository at this point in the history
during models

Fixes #18263
  • Loading branch information
nyalldawson committed Mar 5, 2018
1 parent 8543a91 commit 84cdd60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsprocessingalgorithm.h"
#include "qgsvectorlayerfeatureiterator.h"
#include "qgsexpressioncontextscopegenerator.h"
#include "qgsfileutils.h"

QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
{
Expand Down Expand Up @@ -539,7 +540,7 @@ QString QgsProcessingUtils::generateTempFilename( const QString &basename )
QDir tmpDir;
tmpDir.mkdir( path );
}
return path + '/' + basename;
return path + '/' + QgsFileUtils::stringToSafeFilename( basename );
}

QString QgsProcessingUtils::formatHelpMapAsHtml( const QVariantMap &map, const QgsProcessingAlgorithm *algorithm )
Expand Down
5 changes: 5 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -5797,6 +5797,11 @@ void TestQgsProcessing::tempUtils()
QVERIFY( tempFile1 != tempFile2 );
QVERIFY( tempFile2.endsWith( "test.txt" ) );
QVERIFY( tempFile2.startsWith( tempFolder ) );

// invalid characters
QString tempFile3 = QgsProcessingUtils::generateTempFilename( "mybad:file.txt" );
QVERIFY( tempFile3.endsWith( "mybad_file.txt" ) );
QVERIFY( tempFile3.startsWith( tempFolder ) );
}

void TestQgsProcessing::convertCompatible()
Expand Down

0 comments on commit 84cdd60

Please sign in to comment.