Skip to content
Permalink
Browse files

Fix QgsPathResolver resolving older style relative links (without

any ./ or ../ prefix)
  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent 5b8bea7 commit cf3014ccf2c0f134418bebbc397d652fe7ea1c4e
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/core/qgspathresolver.cpp
  2. +13 −0 tests/src/core/testqgsproject.cpp
@@ -72,7 +72,7 @@ QString QgsPathResolver::readPath( const QString &filename ) const
// from the filename.

QFileInfo pfi( mBaseFileName );
QString home = pfi.absoluteFilePath();
QString home = pfi.absolutePath();
if ( home.isEmpty() )
return vsiPrefix + src;

@@ -108,6 +108,19 @@ void TestQgsProject::testPathResolver()
QCOMPARE( resolverRel.readPath( "../file1.txt" ), QString( "/home/file1.txt" ) );
QCOMPARE( resolverRel.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );

// test older style relative path - file must exist for this to work
QTemporaryFile tmpFile;
tmpFile.open(); // fileName is not available until we open the file
QString tmpName = tmpFile.fileName();
tmpFile.close();
QgsPathResolver tempRel( tmpName );
QFileInfo fi( tmpName );
QFile testFile( fi.path() + QStringLiteral( "/file1.txt" ) );
testFile.open( QIODevice::WriteOnly | QIODevice::Text );
testFile.close();
QVERIFY( QFile::exists( fi.path() + QStringLiteral( "/file1.txt" ) ) );
QCOMPARE( tempRel.readPath( "file1.txt" ), fi.path() + QStringLiteral( "/file1.txt" ) );

QgsPathResolver resolverAbs;
QCOMPARE( resolverAbs.writePath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );
QCOMPARE( resolverAbs.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );

0 comments on commit cf3014c

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