Skip to content
Permalink
Browse files

WMS provider: urlencode layer names in GetMap URL requests

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 93785665fe1a74cbd6980ad6db9d85a6613e4eea
Showing with 20 additions and 2 deletions.
  1. +2 −2 src/providers/wms/qgswmsprovider.cpp
  2. +18 −0 tests/src/providers/testqgswmsprovider.cpp
@@ -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;
@@ -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 );

0 comments on commit 9378566

Please sign in to comment.