Skip to content

Commit f8bbdf5

Browse files
authored
Merge pull request #8389 from elpaso/bugfix-20271-wms-null-styles-backport
[wms] Do not pass null QStrings to QgsWmsProvider::setQueryItem
2 parents cb5c326 + d754ecf commit f8bbdf5

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/providers/wms/qgswmsprovider.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,10 @@ bool QgsWmsProvider::setImageCrs( QString const &crs )
482482
void QgsWmsProvider::setQueryItem( QUrl &url, const QString &item, const QString &value )
483483
{
484484
url.removeQueryItem( item );
485-
url.addQueryItem( item, value );
485+
if ( value.isNull() )
486+
url.addQueryItem( item, QStringLiteral( "" ) ); // skip-keyword-check
487+
else
488+
url.addQueryItem( item, value );
486489
}
487490

488491
void QgsWmsProvider::setFormatQueryItem( QUrl &url )

src/providers/wms/qgswmsprovider.h

+3
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ class QgsWmsProvider : public QgsRasterDataProvider
461461

462462
//! User's settings (URI, authorization, layer, style, ...)
463463
QgsWmsSettings mSettings;
464+
465+
friend class TestQgsWmsProvider;
466+
464467
};
465468

466469

tests/src/providers/testqgswmsprovider.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ class TestQgsWmsProvider: public QObject
7676
QCOMPARE( provider.getLegendGraphicUrl(), QString( "http://localhost:8380/mapserv?" ) );
7777
}
7878

79+
// regression #20271 - WMS is not displayed in QGIS 3.4.0
80+
void queryItemsWithNullValue()
81+
{
82+
QString failingAddress( "http://localhost:8380/mapserv" );
83+
QgsWmsProvider provider( failingAddress, QgsDataProvider::ProviderOptions(), mCapabilities );
84+
QUrl url( provider.createRequestUrlWMS( QgsRectangle( 0, 0, 90, 90 ), 100, 100 ) );
85+
QCOMPARE( url.toString(), QString( "http://localhost:8380/mapserv?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap"
86+
"&BBOX=0,0,90,90&CRS=CRS:84&WIDTH=100&HEIGHT=100&LAYERS=&"
87+
"STYLES=&FORMAT=&TRANSPARENT=TRUE" ) );
88+
}
89+
7990
private:
8091
QgsWmsCapabilities *mCapabilities = nullptr;
8192
};

0 commit comments

Comments
 (0)