Skip to content
Permalink
Browse files

Merge pull request #9099 from elpaso/bugfix-21150-file-protocol-path-…

…resolver

Strip file:// from local files path before resolving

Cherry-picked from master 185855b
  • Loading branch information
elpaso authored and nyalldawson committed Feb 5, 2019
1 parent 2831a02 commit 110c0ac3c7dee1b566b63e34d43355d03bfdf073
Showing with 22 additions and 1 deletion.
  1. +2 −1 src/core/qgspathresolver.cpp
  2. +20 −0 tests/src/core/testqgsproject.cpp
@@ -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
@@ -41,6 +41,7 @@ class TestQgsProject : public QObject
void testProjectUnits();
void variablesChanged();
void testLayerFlags();
void testLocalFiles();
};

void TestQgsProject::init()
@@ -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 110c0ac

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