Skip to content
Permalink
Browse files

Handle windows path in gdal provider's decodeUri function

  • Loading branch information
nirvn committed Sep 14, 2018
1 parent b970370 commit 7d4a4eb5ca6086e6f1747d0dc70af1a9f2255338
Showing with 17 additions and 3 deletions.
  1. +11 −3 src/providers/gdal/qgsgdalprovider.cpp
  2. +6 −0 tests/src/providers/testqgsgdalprovider.cpp
@@ -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;
@@ -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()

0 comments on commit 7d4a4eb

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