Skip to content

Commit

Permalink
Strip file:// from local files path before resolving
Browse files Browse the repository at this point in the history
Fixes #21150 - Delimitedtext layer saves absolute path
when project in relative path mode
  • Loading branch information
elpaso committed Feb 5, 2019
1 parent 109fcc0 commit 22c22e8
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 22c22e8

Please sign in to comment.