Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9099 from elpaso/bugfix-21150-file-protocol-path-…
…resolver

Strip file:// from local files path before resolving
  • Loading branch information
elpaso committed Feb 5, 2019
2 parents 6413349 + 22c22e8 commit 185855b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/qgspathresolver.cpp
Expand Up @@ -163,7 +163,8 @@ QString QgsPathResolver::writePath( const QString &src ) const
return src;
}

QFileInfo srcFileInfo( src );
// Strip "file://"
QFileInfo srcFileInfo( src.startsWith( QStringLiteral( "file://" ) ) ? src.mid( 7 ) : src );
QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;

// if this is a VSIFILE, remove the VSI prefix and append to final result
Expand Down
20 changes: 20 additions & 0 deletions tests/src/core/testqgsproject.cpp
Expand Up @@ -41,6 +41,7 @@ class TestQgsProject : public QObject
void testProjectUnits();
void variablesChanged();
void testLayerFlags();
void testLocalFiles();
};

void TestQgsProject::init()
Expand Down Expand Up @@ -386,6 +387,25 @@ void TestQgsProject::testLayerFlags()
QVERIFY( !layer->flags().testFlag( QgsMapLayer::Removable ) );
}

void TestQgsProject::testLocalFiles()
{
QTemporaryFile f;
QVERIFY( f.open() );
f.close();
QgsProject prj;
QFileInfo info( f.fileName() );
prj.setFileName( f.fileName() );
prj.write();
QString shpPath = info.dir().path() + '/' + info.baseName() + ".shp";
QString layerPath = "file://" + shpPath;
QFile f2( shpPath );
QVERIFY( f2.open( QFile::ReadWrite ) );
f2.close();
QgsPathResolver resolver( f.fileName( ) );
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" ) ) ;

}


QGSTEST_MAIN( TestQgsProject )
#include "testqgsproject.moc"

0 comments on commit 185855b

Please sign in to comment.