Skip to content

Commit

Permalink
Fix path resolver sometimes returns non empty paths while resolving e…
Browse files Browse the repository at this point in the history
…mpty filenames

(cherry-picked from 3e31a65)
  • Loading branch information
nyalldawson committed Jul 28, 2018
1 parent 0f7336e commit cbb6838
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/qgspathresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ QgsPathResolver::QgsPathResolver( const QString &baseFileName )

QString QgsPathResolver::readPath( const QString &filename ) const
{
if ( filename.isEmpty() )
return QString();

QString src = filename;

if ( mBaseFileName.isNull() )
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void TestQgsProject::testPathResolver()
{
// Test resolver with a non existing file path
QgsPathResolver resolverLegacy( QStringLiteral( "/home/qgis/test.qgs" ) );
QCOMPARE( resolverLegacy.readPath( QString() ), QString() );
QCOMPARE( resolverLegacy.writePath( QString() ), QString() );
QCOMPARE( resolverLegacy.writePath( "/home/qgis/file1.txt" ), QString( "./file1.txt" ) );
QCOMPARE( resolverLegacy.writePath( "/home/qgis/subdir/file1.txt" ), QString( "./subdir/file1.txt" ) );
QCOMPARE( resolverLegacy.writePath( "/home/file1.txt" ), QString( "../file1.txt" ) );
Expand All @@ -117,6 +119,8 @@ void TestQgsProject::testPathResolver()
dir.mkpath( tmpDirName + "/home/qgis/" );

QgsPathResolver resolverRel( QString( tmpDirName + "/home/qgis/test.qgs" ) );
QCOMPARE( resolverRel.readPath( QString() ), QString() );
QCOMPARE( resolverRel.writePath( QString() ), QString() );
QCOMPARE( resolverRel.writePath( tmpDirName + "/home/qgis/file1.txt" ), QString( "./file1.txt" ) );
QCOMPARE( resolverRel.writePath( tmpDirName + "/home/qgis/subdir/file1.txt" ), QString( "./subdir/file1.txt" ) );
QCOMPARE( resolverRel.writePath( tmpDirName + "/home/file1.txt" ), QString( "../file1.txt" ) );
Expand Down

0 comments on commit cbb6838

Please sign in to comment.