Skip to content

Commit

Permalink
Handle windows path in gdal provider's decodeUri function
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Sep 14, 2018
1 parent b970370 commit 7d4a4eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,9 +1994,17 @@ QGISEXTERN QVariantMap decodeUri( const QString &uri )
if ( path.indexOf( ':' ) != -1 )
{
QStringList parts = path.split( ':' );
path = parts[1];
if ( parts.count() > 2 )
layerName = parts[2];
if ( parts[0].toLower() == QStringLiteral( "gpkg" ) )
{
parts.removeFirst();
// Handle windows paths - which has an extra colon - and unix paths
if ( ( parts[0].length() > 1 && parts.count() > 1 ) || parts.count() > 2 )
{
layerName = parts[parts.length() - 1];
parts.removeLast();
}
path = parts.join( ':' );
}
}

QVariantMap uriComponents;
Expand Down
6 changes: 6 additions & 0 deletions tests/src/providers/testqgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ void TestQgsGdalProvider::decodeUri()
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
QCOMPARE( components[QStringLiteral( "path" )].toString(), QStringLiteral( "/home/to/path/my_file.gpkg" ) );
QCOMPARE( components[QStringLiteral( "layerName" )].toString(), QStringLiteral( "layer_name" ) );

//test windows path
uri = QStringLiteral( "gpkg:c:/home/to/path/my_file.gpkg:layer_name" );
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
QCOMPARE( components[QStringLiteral( "path" )].toString(), QStringLiteral( "c:/home/to/path/my_file.gpkg" ) );
QCOMPARE( components[QStringLiteral( "layerName" )].toString(), QStringLiteral( "layer_name" ) );
}

void TestQgsGdalProvider::scaleDataType()
Expand Down

0 comments on commit 7d4a4eb

Please sign in to comment.