Skip to content

Commit 7d4a4eb

Browse files
committed
Handle windows path in gdal provider's decodeUri function
1 parent b970370 commit 7d4a4eb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -1994,9 +1994,17 @@ QGISEXTERN QVariantMap decodeUri( const QString &uri )
19941994
if ( path.indexOf( ':' ) != -1 )
19951995
{
19961996
QStringList parts = path.split( ':' );
1997-
path = parts[1];
1998-
if ( parts.count() > 2 )
1999-
layerName = parts[2];
1997+
if ( parts[0].toLower() == QStringLiteral( "gpkg" ) )
1998+
{
1999+
parts.removeFirst();
2000+
// Handle windows paths - which has an extra colon - and unix paths
2001+
if ( ( parts[0].length() > 1 && parts.count() > 1 ) || parts.count() > 2 )
2002+
{
2003+
layerName = parts[parts.length() - 1];
2004+
parts.removeLast();
2005+
}
2006+
path = parts.join( ':' );
2007+
}
20002008
}
20012009

20022010
QVariantMap uriComponents;

tests/src/providers/testqgsgdalprovider.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void TestQgsGdalProvider::decodeUri()
9595
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
9696
QCOMPARE( components[QStringLiteral( "path" )].toString(), QStringLiteral( "/home/to/path/my_file.gpkg" ) );
9797
QCOMPARE( components[QStringLiteral( "layerName" )].toString(), QStringLiteral( "layer_name" ) );
98+
99+
//test windows path
100+
uri = QStringLiteral( "gpkg:c:/home/to/path/my_file.gpkg:layer_name" );
101+
components = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri );
102+
QCOMPARE( components[QStringLiteral( "path" )].toString(), QStringLiteral( "c:/home/to/path/my_file.gpkg" ) );
103+
QCOMPARE( components[QStringLiteral( "layerName" )].toString(), QStringLiteral( "layer_name" ) );
98104
}
99105

100106
void TestQgsGdalProvider::scaleDataType()

0 commit comments

Comments
 (0)