Skip to content

Commit

Permalink
Fix creation of GeoPDF with exported themes containing slashes
Browse files Browse the repository at this point in the history
Fixes #51480
  • Loading branch information
nyalldawson committed Feb 1, 2023
1 parent 9d7dae6 commit 83e7b2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/qgsabstractgeopdfexporter.cpp
Expand Up @@ -123,7 +123,10 @@ bool QgsAbstractGeoPdfExporter::finalize( const QList<ComponentLayerDetail> &com

QString QgsAbstractGeoPdfExporter::generateTemporaryFilepath( const QString &filename ) const
{
return mTemporaryDir.filePath( filename );
QString cleanedFileName = filename;
cleanedFileName.replace( '\\', '_' );
cleanedFileName.replace( '/', '_' );
return mTemporaryDir.filePath( cleanedFileName );
}

bool QgsAbstractGeoPdfExporter::compositionModeSupported( QPainter::CompositionMode mode )
Expand Down
18 changes: 18 additions & 0 deletions tests/src/core/testqgslayoutgeopdfexport.cpp
Expand Up @@ -37,6 +37,7 @@ class TestQgsLayoutGeoPdfExport : public QgsTest
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void testTempFilenames();
void testCollectingFeatures();
void skipLayers();
void layerOrder();
Expand All @@ -53,6 +54,23 @@ void TestQgsLayoutGeoPdfExport::cleanupTestCase()
QgsApplication::exitQgis();
}

void TestQgsLayoutGeoPdfExport::testTempFilenames()
{
QgsProject p;
QgsLayout l( &p );
QgsLayoutGeoPdfExporter geoPdfExporter( &l );

QString outputFile = geoPdfExporter.generateTemporaryFilepath( QStringLiteral( "test_src.pdf" ) );
QVERIFY( outputFile.endsWith( QStringLiteral( "test_src.pdf" ) ) );

// test generating temporary file path with slash characters (https://github.com/qgis/QGIS/issues/51480)
outputFile = geoPdfExporter.generateTemporaryFilepath( QStringLiteral( "test/ src.pdf" ) );
QVERIFY( outputFile.endsWith( QStringLiteral( "test_ src.pdf" ) ) );

outputFile = geoPdfExporter.generateTemporaryFilepath( QStringLiteral( "test\\ src.pdf" ) );
QVERIFY( outputFile.endsWith( QStringLiteral( "test_ src.pdf" ) ) );
}

void TestQgsLayoutGeoPdfExport::testCollectingFeatures()
{
QgsVectorLayer *linesLayer = new QgsVectorLayer( TEST_DATA_DIR + QStringLiteral( "/lines.shp" ),
Expand Down

0 comments on commit 83e7b2c

Please sign in to comment.