Skip to content

Commit 185855b

Browse files
authoredFeb 5, 2019
Merge pull request #9099 from elpaso/bugfix-21150-file-protocol-path-resolver
Strip file:// from local files path before resolving
2 parents 6413349 + 22c22e8 commit 185855b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
 

‎src/core/qgspathresolver.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ QString QgsPathResolver::writePath( const QString &src ) const
163163
return src;
164164
}
165165

166-
QFileInfo srcFileInfo( src );
166+
// Strip "file://"
167+
QFileInfo srcFileInfo( src.startsWith( QStringLiteral( "file://" ) ) ? src.mid( 7 ) : src );
167168
QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
168169

169170
// if this is a VSIFILE, remove the VSI prefix and append to final result

‎tests/src/core/testqgsproject.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TestQgsProject : public QObject
4141
void testProjectUnits();
4242
void variablesChanged();
4343
void testLayerFlags();
44+
void testLocalFiles();
4445
};
4546

4647
void TestQgsProject::init()
@@ -386,6 +387,25 @@ void TestQgsProject::testLayerFlags()
386387
QVERIFY( !layer->flags().testFlag( QgsMapLayer::Removable ) );
387388
}
388389

390+
void TestQgsProject::testLocalFiles()
391+
{
392+
QTemporaryFile f;
393+
QVERIFY( f.open() );
394+
f.close();
395+
QgsProject prj;
396+
QFileInfo info( f.fileName() );
397+
prj.setFileName( f.fileName() );
398+
prj.write();
399+
QString shpPath = info.dir().path() + '/' + info.baseName() + ".shp";
400+
QString layerPath = "file://" + shpPath;
401+
QFile f2( shpPath );
402+
QVERIFY( f2.open( QFile::ReadWrite ) );
403+
f2.close();
404+
QgsPathResolver resolver( f.fileName( ) );
405+
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" ) ) ;
406+
407+
}
408+
389409

390410
QGSTEST_MAIN( TestQgsProject )
391411
#include "testqgsproject.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.