Skip to content
Permalink
Browse files

Merge pull request #33925 from elpaso/bugfix-gh33200-pathresolver-fai…

…ls-with-relative-project-paths

Fix pathresolver failure when project is relative
  • Loading branch information
elpaso committed Jan 22, 2020
2 parents 8e5818d + 399637b commit db322365adeac5197e708150db856478ee40f030
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').replace("\\", "/"), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp').replace("\\", "/"))
self.assertEqual(resolver.readPath('testlayer.shp').replace("\\", "/"), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp').replace("\\", "/"))
resolver = QgsPathResolver('test_project.qgs')
self.assertEqual(resolver.readPath('./testlayer.shp').replace("\\", "/"), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp').replace("\\", "/"))
self.assertEqual(resolver.readPath('testlayer.shp').replace("\\", "/"), os.path.join(TEST_DATA_DIR, 'qgis_server', 'testlayer.shp').replace("\\", "/"))
os.chdir(curdir)


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

0 comments on commit db32236

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