Skip to content

Commit

Permalink
fix explicit vsicurl prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
notguiltyspark committed Dec 11, 2024
1 parent e9e7bc5 commit edfa0ba
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/gui/ogr/qgsgdalguiutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,20 @@ QString QgsGdalGuiUtils::createDatabaseURI( const QString &connectionType, const

QString QgsGdalGuiUtils::createProtocolURI( const QString &type, const QString &url, const QString &configId, const QString &username, const QString &password, bool expandAuthConfig )
{
QString uri;
QString uri = url;
QString prefix;
if ( type == QLatin1String( "vsicurl" ) )
{
uri = url;
// If no protocol is provided in the URL, default to HTTP
if ( !uri.startsWith( "http://" ) && !uri.startsWith( "https://" ) && !uri.startsWith( "ftp://" ) )
prefix = QStringLiteral( "/vsicurl/" );
if ( !uri.startsWith( prefix ) )
{
uri.prepend( QStringLiteral( "http://" ) );
// If no protocol is provided in the URL, default to HTTP
if ( !uri.startsWith( QLatin1String( "http://" ) ) && !uri.startsWith( QLatin1String( "https://" ) ) && !uri.startsWith( QLatin1String( "ftp://" ) ) )
{
uri.prepend( QStringLiteral( "http://" ) );
}
uri.prepend( prefix );
}
uri.prepend( QStringLiteral( "/vsicurl/" ) );
}
else if ( type == QLatin1String( "vsis3" )
|| type == QLatin1String( "vsigs" )
Expand All @@ -241,25 +245,40 @@ QString QgsGdalGuiUtils::createProtocolURI( const QString &type, const QString &
|| type == QLatin1String( "vsiswift" )
|| type == QLatin1String( "vsihdfs" ) )
{
uri = url;
uri.prepend( QStringLiteral( "/%1/" ).arg( type ) );
prefix = QStringLiteral( "/%1/" ).arg( type );
if ( !uri.startsWith( prefix ) )
{
uri.prepend( prefix );
}
}
// catching both GeoJSON and GeoJSONSeq
else if ( type.startsWith( QLatin1String( "GeoJSON" ) ) )
{
uri = url;
// no change needed for now
}
else if ( type == QLatin1String( "CouchDB" ) )
{
uri = QStringLiteral( "couchdb:%1" ).arg( url );
prefix = QStringLiteral( "couchdb:" );
if ( !uri.startsWith( prefix ) )
{
uri.prepend( prefix );
}
}
else if ( type == QLatin1String( "DODS/OPeNDAP" ) )
{
uri = QStringLiteral( "DODS:%1" ).arg( url );
prefix = QStringLiteral( "DODS:" );
if ( !uri.startsWith( prefix ) )
{
uri.prepend( prefix );
}
}
else if ( type == QLatin1String( "WFS3" ) )
{
uri = QStringLiteral( "WFS3:%1" ).arg( url );
prefix = QStringLiteral( "WFS3:" );
if ( !uri.startsWith( prefix ) )
{
uri.prepend( prefix );
}
}
QgsDebugMsgLevel( "Connection type is=" + type + " and uri=" + uri, 2 );
// Update URI with authentication information
Expand Down
1 change: 1 addition & 0 deletions tests/src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set(TESTS
testqgsmessagebar.cpp
testprojectionissues.cpp
testqgsgui.cpp
testqgsgdalguiutils.cpp
testprocessinggui.cpp
testqgsprocessingmodel.cpp
testqgsrubberband.cpp
Expand Down
Loading

0 comments on commit edfa0ba

Please sign in to comment.