Skip to content

Commit

Permalink
WMS provider: urlencode layer names in GetMap URL requests
Browse files Browse the repository at this point in the history
Fixes #41116

Successfully tested on QGIS Server and GeoServer

(cherry picked from commit 3ca980f)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 8829430 commit 9378566
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -1042,8 +1042,8 @@ QUrl QgsWmsProvider::createRequestUrlWMS( const QgsRectangle &viewExtent, int pi
{
if ( mActiveSubLayerVisibility.constFind( *it ).value() )
{
visibleLayers += *it;
visibleStyles += *it2;
visibleLayers += QUrl::toPercentEncoding( *it );
visibleStyles += QUrl::toPercentEncoding( *it2 );
}

++it2;
Expand Down
18 changes: 18 additions & 0 deletions tests/src/providers/testqgswmsprovider.cpp
Expand Up @@ -101,6 +101,24 @@ class TestQgsWmsProvider: public QObject
"STYLES=&FORMAT=&TRANSPARENT=TRUE" ) );
}

// regression #41116
void queryItemsWithPlusSign()
{
const QString failingAddress( "layers=plus+sign&styles=&url=http://localhost:8380/mapserv" );
const QgsWmsParserSettings config;
QgsWmsCapabilities cap;
QFile file( QStringLiteral( TEST_DATA_DIR ) + "/provider/GetCapabilities.xml" );
QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) );
const QByteArray content = file.readAll().replace( "<Name>test</Name>", "<Name>plus+sign</Name>" );
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&"
"LAYERS=plus%2Bsign&STYLES=&FORMAT=&TRANSPARENT=TRUE" ) );
}


void noCrsSpecified()
{
QgsWmsProvider provider( QStringLiteral( "http://localhost:8380/mapserv?xxx&layers=agri_zones&styles=&format=image/jpg" ), QgsDataProvider::ProviderOptions(), mCapabilities );
Expand Down

0 comments on commit 9378566

Please sign in to comment.