Skip to content

Commit cf3014c

Browse files
committed
Fix QgsPathResolver resolving older style relative links (without
any ./ or ../ prefix)
1 parent 5b8bea7 commit cf3014c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core/qgspathresolver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ QString QgsPathResolver::readPath( const QString &filename ) const
7272
// from the filename.
7373

7474
QFileInfo pfi( mBaseFileName );
75-
QString home = pfi.absoluteFilePath();
75+
QString home = pfi.absolutePath();
7676
if ( home.isEmpty() )
7777
return vsiPrefix + src;
7878

tests/src/core/testqgsproject.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ void TestQgsProject::testPathResolver()
108108
QCOMPARE( resolverRel.readPath( "../file1.txt" ), QString( "/home/file1.txt" ) );
109109
QCOMPARE( resolverRel.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );
110110

111+
// test older style relative path - file must exist for this to work
112+
QTemporaryFile tmpFile;
113+
tmpFile.open(); // fileName is not available until we open the file
114+
QString tmpName = tmpFile.fileName();
115+
tmpFile.close();
116+
QgsPathResolver tempRel( tmpName );
117+
QFileInfo fi( tmpName );
118+
QFile testFile( fi.path() + QStringLiteral( "/file1.txt" ) );
119+
testFile.open( QIODevice::WriteOnly | QIODevice::Text );
120+
testFile.close();
121+
QVERIFY( QFile::exists( fi.path() + QStringLiteral( "/file1.txt" ) ) );
122+
QCOMPARE( tempRel.readPath( "file1.txt" ), fi.path() + QStringLiteral( "/file1.txt" ) );
123+
111124
QgsPathResolver resolverAbs;
112125
QCOMPARE( resolverAbs.writePath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );
113126
QCOMPARE( resolverAbs.readPath( "/home/qgis/file1.txt" ), QString( "/home/qgis/file1.txt" ) );

0 commit comments

Comments
 (0)