Skip to content

Commit

Permalink
SERVER: Fix server utils service URL wrong MAP replace
Browse files Browse the repository at this point in the history
Fixes #54533

Backported from master
  • Loading branch information
elpaso committed Oct 5, 2023
1 parent a16d558 commit b36e247
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/server/qgsserverprojectutils.cpp
Expand Up @@ -407,7 +407,17 @@ QString QgsServerProjectUtils::serviceUrl( const QString &service, const QgsServ
}

// https://docs.qgis.org/3.16/en/docs/server_manual/services.html#wms-map
const QString map = QUrlQuery( request.originalUrl().query().replace( QLatin1String( "MAP" ), QStringLiteral( "MAP" ), Qt::CaseInsensitive ) ).queryItemValue( QStringLiteral( "MAP" ) );
const QUrlQuery query { request.originalUrl().query() };
const QList<QPair<QString, QString>> constItems { query.queryItems( ) };
QString map;
for ( const QPair<QString, QString> &item : std::as_const( constItems ) )
{
if ( 0 == item.first.compare( QLatin1String( "MAP" ), Qt::CaseSensitivity::CaseInsensitive ) )
{
map = item.second;
break;
}
}

if ( ! map.isEmpty() )
{
Expand Down
16 changes: 13 additions & 3 deletions tests/src/python/test_qgsserver_projectutils.py
Expand Up @@ -15,9 +15,9 @@
import os

from qgis.core import QgsProject
from qgis.server import QgsServerProjectUtils
from qgis.testing import unittest

from qgis.server import QgsServerProjectUtils, QgsServerSettings, QgsBufferServerRequest
from qgis.testing import unittest, start_app
from unittest import mock
from utilities import unitTestDataPath


Expand Down Expand Up @@ -80,6 +80,16 @@ def test_wcslayersids(self):

self.assertEqual(expected, result)

@mock.patch.dict(os.environ, {"QGIS_SERVER_WFS_SERVICE_URL": "http://localhost:8080"})
def test_map_uppercase_replace(self):
"""Test issue GH #54533 MAP replacementin URL arg"""

settings = QgsServerSettings()
self.assertIsNotNone(settings.serviceUrl('WFS'))
request = QgsBufferServerRequest('http://localhost:8080/?MaP=/mAp.qgs&SERVICE=WMS&REQUEST=GetMap')
service_url = QgsServerProjectUtils.serviceUrl('WFS', request, settings)
self.assertEqual(service_url, 'http://localhost:8080/?MAP=/mAp.qgs')


if __name__ == '__main__':
unittest.main()

0 comments on commit b36e247

Please sign in to comment.