Skip to content

Commit

Permalink
[WMS provider] Detection of SERVICE=WMTS in url must be case insensitive
Browse files Browse the repository at this point in the history
As mandated by OGC specs.

Fixes #36659
  • Loading branch information
rouault committed May 27, 2020
1 parent 2a70569 commit 97bac49
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -2344,8 +2344,7 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
mIsAborted = false;

QString url = mBaseUrl;
if ( !url.contains( QLatin1String( "SERVICE=WMTS" ), Qt::CaseInsensitive ) &&
!url.contains( QLatin1String( "/WMTSCapabilities.xml" ), Qt::CaseInsensitive ) )
if ( !QgsWmsProvider::isUrlForWMTS( url ) )
{
url += QLatin1String( "SERVICE=WMS&REQUEST=GetCapabilities" );
}
Expand Down
12 changes: 10 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -197,7 +197,7 @@ QString QgsWmsProvider::prepareUri( QString uri )
// some services provide a percent/url encoded (legend) uri string, always decode here
uri = QUrl::fromPercentEncoding( uri.toUtf8() );

if ( uri.contains( QLatin1String( "SERVICE=WMTS" ) ) || uri.contains( QLatin1String( "/WMTSCapabilities.xml" ) ) )
if ( isUrlForWMTS( uri ) )
{
return uri;
}
Expand Down Expand Up @@ -3652,7 +3652,7 @@ QUrl QgsWmsProvider::getLegendGraphicFullURL( double scale, const QgsRectangle &
QUrl url( lurl );
QUrlQuery query( url );

if ( dataSourceUri().contains( "SERVICE=WMTS" ) || dataSourceUri().contains( "/WMTSCapabilities.xml" ) )
if ( isUrlForWMTS( dataSourceUri() ) )
{
QgsDebugMsg( QString( "getlegendgraphicrequest: %1" ).arg( url.toString() ) );
return url;
Expand Down Expand Up @@ -3865,6 +3865,14 @@ void QgsWmsProvider::getLegendGraphicReplyProgress( qint64 bytesReceived, qint64
emit statusChanged( msg );
}

bool QgsWmsProvider::isUrlForWMTS( const QString &url )
{
// Do comparison in case insensitive way to match OGC KVP requirements
return url.contains( QLatin1String( "SERVICE=WMTS" ), Qt::CaseInsensitive ) ||
url.contains( QLatin1String( "/WMTSCapabilities.xml" ), Qt::CaseInsensitive );
}


QgsWmsProvider *QgsWmsProviderMetadata::createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options )
{
return new QgsWmsProvider( uri, options );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -261,6 +261,8 @@ class QgsWmsProvider final: public QgsRasterDataProvider
} TilePosition;
typedef QList<TilePosition> TilePositions;

static bool isUrlForWMTS( const QString &url );

private slots:
void identifyReplyFinished();
void getLegendGraphicReplyFinished( const QImage & );
Expand Down

0 comments on commit 97bac49

Please sign in to comment.