Skip to content

Commit 5ac18f0

Browse files
fix explicit vsicurl prefix
1 parent 340861d commit 5ac18f0

File tree

3 files changed

+367
-12
lines changed

3 files changed

+367
-12
lines changed

src/gui/ogr/qgsgdalguiutils.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,20 @@ QString QgsGdalGuiUtils::createDatabaseURI( const QString &connectionType, const
222222

223223
QString QgsGdalGuiUtils::createProtocolURI( const QString &type, const QString &url, const QString &configId, const QString &username, const QString &password, bool expandAuthConfig )
224224
{
225-
QString uri;
225+
QString uri = url;
226+
QString prefix;
226227
if ( type == QLatin1String( "vsicurl" ) )
227228
{
228-
uri = url;
229-
// If no protocol is provided in the URL, default to HTTP
230-
if ( !uri.startsWith( "http://" ) && !uri.startsWith( "https://" ) && !uri.startsWith( "ftp://" ) )
229+
prefix = QStringLiteral( "/vsicurl/" );
230+
if ( !uri.startsWith( prefix ) )
231231
{
232-
uri.prepend( QStringLiteral( "http://" ) );
232+
// If no protocol is provided in the URL, default to HTTP
233+
if ( !uri.startsWith( QLatin1String( "http://" ) ) && !uri.startsWith( QLatin1String( "https://" ) ) && !uri.startsWith( QLatin1String( "ftp://" ) ) )
234+
{
235+
uri.prepend( QStringLiteral( "http://" ) );
236+
}
237+
uri.prepend( prefix );
233238
}
234-
uri.prepend( QStringLiteral( "/vsicurl/" ) );
235239
}
236240
else if ( type == QLatin1String( "vsis3" )
237241
|| type == QLatin1String( "vsigs" )
@@ -241,25 +245,40 @@ QString QgsGdalGuiUtils::createProtocolURI( const QString &type, const QString &
241245
|| type == QLatin1String( "vsiswift" )
242246
|| type == QLatin1String( "vsihdfs" ) )
243247
{
244-
uri = url;
245-
uri.prepend( QStringLiteral( "/%1/" ).arg( type ) );
248+
prefix = QStringLiteral( "/%1/" ).arg( type );
249+
if ( !uri.startsWith( prefix ) )
250+
{
251+
uri.prepend( prefix );
252+
}
246253
}
247254
// catching both GeoJSON and GeoJSONSeq
248255
else if ( type.startsWith( QLatin1String( "GeoJSON" ) ) )
249256
{
250-
uri = url;
257+
// no change needed for now
251258
}
252259
else if ( type == QLatin1String( "CouchDB" ) )
253260
{
254-
uri = QStringLiteral( "couchdb:%1" ).arg( url );
261+
prefix = QStringLiteral( "couchdb:" );
262+
if ( !uri.startsWith( prefix ) )
263+
{
264+
uri.prepend( prefix );
265+
}
255266
}
256267
else if ( type == QLatin1String( "DODS/OPeNDAP" ) )
257268
{
258-
uri = QStringLiteral( "DODS:%1" ).arg( url );
269+
prefix = QStringLiteral( "DODS:" );
270+
if ( !uri.startsWith( prefix ) )
271+
{
272+
uri.prepend( prefix );
273+
}
259274
}
260275
else if ( type == QLatin1String( "WFS3" ) )
261276
{
262-
uri = QStringLiteral( "WFS3:%1" ).arg( url );
277+
prefix = QStringLiteral( "WFS3:" );
278+
if ( !uri.startsWith( prefix ) )
279+
{
280+
uri.prepend( prefix );
281+
}
263282
}
264283
QgsDebugMsgLevel( "Connection type is=" + type + " and uri=" + uri, 2 );
265284
// Update URI with authentication information

tests/src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(TESTS
4646
testqgsmessagebar.cpp
4747
testprojectionissues.cpp
4848
testqgsgui.cpp
49+
testqgsgdalguiutils.cpp
4950
testprocessinggui.cpp
5051
testqgsprocessingmodel.cpp
5152
testqgsrubberband.cpp

0 commit comments

Comments
 (0)