Skip to content
Permalink
Browse files

Fix pathresolver failure when project is relative

Fixes #33200 when (server) project was loaded from
the FCGI current directory with a relative path
or not path at all: the pathresolver assumed the
project file path was absolute, which wasn't the
case in this issue.

By forcing the project path to absolute, the
problem goes away.
  • Loading branch information
elpaso committed Jan 20, 2020
1 parent d39b6ac commit 9781c4acf63986d3f5ea3ca659018af0c59a048d
Showing with 16 additions and 0 deletions.
  1. +3 −0 src/core/qgspathresolver.cpp
  2. +13 −0 tests/src/python/test_qgspathresolver.py
@@ -121,6 +121,9 @@ QString QgsPathResolver::readPath( const QString &f ) const
bool uncPath = projPath.startsWith( "//" );
#endif

// Make sure the path is absolute (see GH #33200)
projPath = QFileInfo( projPath ).absoluteFilePath();

QStringList srcElems = srcPath.split( '/', QString::SkipEmptyParts );
QStringList projElems = projPath.split( '/', QString::SkipEmptyParts );

@@ -144,6 +144,19 @@ def testInbuiltPath(self):

self.assertEqual(QgsPathResolver().writePath(QgsApplication.pkgDataPath() + '/resources/data/world_map.shp'), 'inbuilt:/data/world_map.shp')

def testRelativeProject(self):
"""Test relative project paths can still resolve, regression #33200"""

curdir = os.getcwd()
os.chdir(os.path.join(TEST_DATA_DIR, 'qgis_server'))
resolver = QgsPathResolver('./test_project.qgs')
self.assertEqual(resolver.readPath('./testlayer.shp'), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp'))
self.assertEqual(resolver.readPath('testlayer.shp'), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp'))
resolver = QgsPathResolver('test_project.qgs')
self.assertEqual(resolver.readPath('./testlayer.shp'), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp'))
self.assertEqual(resolver.readPath('testlayer.shp'), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp'))
os.chdir(curdir)


if __name__ == '__main__':
unittest.main()

0 comments on commit 9781c4a

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