Skip to content

Commit

Permalink
Fix QgsPathResolver resolving older style relative links (without
Browse files Browse the repository at this point in the history
any ./ or ../ prefix)
  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent 5b8bea7 commit cf3014c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgspathresolver.cpp
Expand Up @@ -72,7 +72,7 @@ QString QgsPathResolver::readPath( const QString &filename ) const
// from the filename. // from the filename.


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


Expand Down
13 changes: 13 additions & 0 deletions tests/src/core/testqgsproject.cpp
Expand Up @@ -108,6 +108,19 @@ void TestQgsProject::testPathResolver()
QCOMPARE( resolverRel.readPath( "../file1.txt" ), QString( "/home/file1.txt" ) ); QCOMPARE( resolverRel.readPath( "../file1.txt" ), QString( "/home/file1.txt" ) );
QCOMPARE( resolverRel.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/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; QgsPathResolver resolverAbs;
QCOMPARE( resolverAbs.writePath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) ); QCOMPARE( resolverAbs.writePath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );
QCOMPARE( resolverAbs.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) ); QCOMPARE( resolverAbs.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );
Expand Down

0 comments on commit cf3014c

Please sign in to comment.