Skip to content

Commit

Permalink
Ensure query items are percent-encoded as expected by QUrlQuery::addQ…
Browse files Browse the repository at this point in the history
…ueryItem
  • Loading branch information
manisandro committed Mar 4, 2023
1 parent cfaf14a commit 6534769
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,12 @@ bool QgsWmsProvider::setImageCrs( QString const &crs )

void QgsWmsProvider::setQueryItem( QUrlQuery &url, const QString &item, const QString &value )
{
url.removeQueryItem( item );
QString key = QUrl::toPercentEncoding( item );
url.removeQueryItem( key );
if ( value.isNull() )
url.addQueryItem( item, "" );
url.addQueryItem( key, "" );
else
url.addQueryItem( item, value );
url.addQueryItem( key, QUrl::toPercentEncoding( value ) );
}

void QgsWmsProvider::setFormatQueryItem( QUrlQuery &url )
Expand Down Expand Up @@ -1261,8 +1262,8 @@ QUrl QgsWmsProvider::createRequestUrlWMS( const QgsRectangle &viewExtent, int pi
{
if ( mActiveSubLayerVisibility.constFind( *it ).value() )
{
visibleLayers += QUrl::toPercentEncoding( *it );
visibleStyles += QUrl::toPercentEncoding( *it2 );
visibleLayers += *it;
visibleStyles += *it2;
}

++it2;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/providers/testqgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestQgsWmsProvider: public QgsTest
QgsWmsProvider provider( failingAddress, QgsDataProvider::ProviderOptions(), mCapabilities );
QUrl url( provider.createRequestUrlWMS( QgsRectangle( 0, 0, 90, 90 ), 100, 100 ) );
QCOMPARE( url.toString(), QString( "http://localhost:8380/mapserv?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap"
"&BBOX=0,0,90,90&CRS=CRS:84&WIDTH=100&HEIGHT=100&LAYERS=&"
"&BBOX=0%2C0%2C90%2C90&CRS=CRS%3A84&WIDTH=100&HEIGHT=100&LAYERS=&"
"STYLES=&FORMAT=&TRANSPARENT=TRUE" ) );
}

Expand All @@ -116,8 +116,8 @@ class TestQgsWmsProvider: public QgsTest
QVERIFY( cap.parseResponse( content, config ) );
QgsWmsProvider provider( failingAddress, QgsDataProvider::ProviderOptions(), &cap );
QUrl url( provider.createRequestUrlWMS( QgsRectangle( 0, 0, 90, 90 ), 100, 100 ) );
QCOMPARE( url.toString(), QString( "http://localhost:8380/mapserv?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=0,0,90,90&"
"CRS=EPSG:2056&WIDTH=100&HEIGHT=100&"
QCOMPARE( url.toString(), QString( "http://localhost:8380/mapserv?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=0%2C0%2C90%2C90&"
"CRS=EPSG%3A2056&WIDTH=100&HEIGHT=100&"
"LAYERS=plus%2Bsign&STYLES=&FORMAT=&TRANSPARENT=TRUE" ) );
}

Expand Down

0 comments on commit 6534769

Please sign in to comment.